问题
I'm sending the following batch request for getting threads:
POST /batch HTTP/1.1
Host: www.googleapis.com
Accept-Encoding: gzip
User-Agent: Magin (gzip)
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
Content-Type: multipart/mixed; type="application/http"; boundary="737d0154-1999-455c-9886-65d7121a1382"
access_token=accToken"aUser=user
--737d0154-1999-455c-9886-65d7121a1382
Content-Type: application/http
Content-ID: <0x8d93fa0>
GET /gmail/v1/users/me/threads/146df2dd11472f07 HTTP/1.1
Host: googleapis.com
Accept-Encoding: gzip
User-Agent: Magin (gzip)
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
--737d0154-1999-455c-9886-65d7121a1382
Content-Type: application/http
Content-ID: <0x8d93190>
GET /gmail/v1/users/me/threads/146df14c9a13b5d9 HTTP/1.1
Host: googleapis.com
Accept-Encoding: gzip
User-Agent: Magin (gzip)
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
--737d0154-1999-455c-9886-65d7121a1382
Content-Type: application/http
Content-ID: <0x8d93190>
GET /gmail/v1/users/me/threads/146def434891a5b0 HTTP/1.1
Host: googleapis.com
Accept-Encoding: gzip
User-Agent: Magin (gzip)
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
--737d0154-1999-455c-9886-65d7121a1382
Content-Type: application/http
Content-ID: <0x8d93190>
GET /gmail/v1/users/me/threads/146def1dbfe6579c HTTP/1.1
Host: googleapis.com
Accept-Encoding: gzip
User-Agent: Magin (gzip)
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
--737d0154-1999-455c-9886-65d7121a1382
Content-Type: application/http
Content-ID: <0x8d93190>
GET /gmail/v1/users/me/threads/146def155ca0ab2b HTTP/1.1
Host: googleapis.com
Accept-Encoding: gzip
User-Agent: Magin (gzip)
Accept-Language: en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5
--737d0154-1999-455c-9886-65d7121a1382--
However I get 400 bad request as a response from the Google servers: Request failed: bad request (400)
Any ideas why this is happening and how I can fix it?
EDIT: interesting behavior: it works if there are <= 3 batched requests but if there are more it doesn't.
回答1:
two things i notice:
(1) the space before the Content-Type on the first part
(2) missing a final "--737d0154-1999-455c-9886-65d7121a1382--" at the very end of the POST (on it's own line, etc), note the trailing "--" AFTER it the boundary as well...
来源:https://stackoverflow.com/questions/24462015/batch-request-400-bad-request-response