【发布时间】:2015-03-31 08:40:23
【问题描述】:
我正在尝试使用 request 为 nodejs 发送洗澡请求到 GMail API。问题是即使我生成与文档中相同的查询,gmail 总是以 400 BadRequest
响应这些是我的 json 格式的标题
{ 'Content-Type': 'multipart/mixed; boundary=c2db2692-8877-4159-bf02-03e6c5d3ffbf',
authorization: 'Bearer MY_TOKEN',
'content-length': 231 }
正文内容示例
--c2db2692-8877-4159-bf02-03e6c5d3ffbf
Content-Type: application/http
Content-ID: <item1:12930812@barnyard.example.com>
GET /gmail/v1/users/sneg0k32@gmail.com/messages/14c6c0c43e9bb16b
--c2db2692-8877-4159-bf02-03e6c5d3ffbf--
任何建议为什么会发生这种情况? Request 会生成额外的几个空格并将标头设为小写,但我不确定这是否是问题所在。
nodejs代码示例
request({
method: 'POST',
uri: 'https://www.googleapis.com/batch',
auth: {
bearer: key
},
headers: {
'Content-Type': 'multipart/mixed'
},
multipart: _.map(queries, function(query) {
return {
'Content-Type': 'application/http',
'Content-ID': "<item1:12930812@barnyard.example.com>",
body: 'GET ' + query
}
})
}, function(error, response, body) {
console.log(response.request.headers)
_.map(response.request.body, function(chunk) {
console.log(chunk.toString())
})
console.log(body)
})
UPD:这显然是我如何进行节点调用、通过 HTTPTester 发送相同请求并且一切正常的问题
UPD2:决定使用单身汉,但是我还没有弄清楚是什么导致了这个问题的简单请求
【问题讨论】:
标签: node.js google-api gmail