You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Calendar API批量请求报错:Failed to get multipart boundary

Google Calendar API批量请求报错:Failed to get multipart boundary.

问题背景

尝试调用Google Calendar API批量获取日历信息,已参考相关StackOverflow回答及Google官方文档,使用废弃通用端点的替代地址https://www.googleapis.com/batch/calendar/v3作为请求地址,但发送请求后始终返回400错误。

发送的请求体

POST /batch/calendar/v3 HTTP/1.1

Content-Type: multipart/mixed; boundary="batch_foobarbaz"

--batch_foobarbaz
Content-Type: application/http

GET /calendar/v3/calendars/*calendarId1*

--batch_foobarbaz
Content-Type: application/http

GET /calendar/v3/calendars/*calendarId2*

--batch_foobarbaz--

错误响应

{
    "error": {
        "code": 400,
        "message": "Failed to get multipart boundary.",
        "status": "INVALID_ARGUMENT"
    }
}

问题原因及修正方案

请求存在两个核心问题:

  • 请求头与请求体的分隔错误:HTTP规范要求请求头和请求体之间必须用两个连续换行分隔,你当前的请求中Content-Type头后仅一个换行,导致服务器无法识别multipart边界。
  • 子请求格式不完整:每个子HTTP请求需要以两个连续换行结尾,标记单个请求的结束,否则服务器无法正确解析子请求边界。

修正后的完整请求体如下:

POST /batch/calendar/v3 HTTP/1.1
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary="batch_foobarbaz"

--batch_foobarbaz
Content-Type: application/http

GET /calendar/v3/calendars/*calendarId1* HTTP/1.1


--batch_foobarbaz
Content-Type: application/http

GET /calendar/v3/calendars/*calendarId2* HTTP/1.1


--batch_foobarbaz--

关键修正细节

  • 确保Content-Type头后保留两个连续换行,明确分隔请求头与请求体。
  • 每个子GET请求末尾添加两个连续换行,保证子请求的完整性。
  • 显式添加Host头,符合HTTP协议规范,避免客户端自动补全时出现异常。

另外,需将请求中的*calendarId1*和*calendarId2*替换为实际的日历ID,同时确保请求携带有效的身份验证信息(如OAuth 2.0令牌)。

内容的提问来源于stack exchange,提问作者Roel Wetzels

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 16:27:37