获取 Gmail 联系人,无法弄清楚将内容长度设置为多少
我正在尝试使用curl 检索我的联系人。 我已成功获取 authToken,现在收到一条错误,指出我需要在标头中设置内容长度,但当我将内容长度设置为 0 时,我收到“错误请求”错误。 有谁知道内容长度是多少? 是Auth key的长度吗? 或者包含它的整个标头字段的长度? 我只是在黑暗中摸索,谷歌API似乎没有解释它在寻找什么。
I'm trying to retrieve my contacts using curl. I've succeeded in getting my authToken, and now am getting an error stating that I need to set the content-length in the header, but when I set the content length to 0 I get a "bad request" error.
Does anyone know what the content length is? Is it the length of the Auth key? or the length of the entire header field that contains it? I'm just poking around in the dark, and the google api doesn't seem to explain what it's looking for.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据HTTP标准,
内容-length
必须大于或等于零。 如果出现以下情况,此标头可能会导致“错误请求”问题:transfer-encoding
”标头,或者content-length
小于实际长度content-length
内容长度应为消息正文的大小(不包括标头)。 这将包括随请求发送的 POST 数据(大概是您的 authToken 的发送方式)。
发送的长度不需要精确(尽管您应该尝试!)。 大多数浏览器并不关心长度(只要大于实际内容长度即可)。 如果它小于实际的内容长度,大多数浏览器都会阻塞,但反之则不然。 我假设谷歌的服务器也会有类似的行为。
According to the HTTP standard,
content-length
must be greater then or equal to zero. This header can cause a "bad request" problem if:transfer-encoding
' header is included in the request with certain values orcontent-length
is less than the actual lengthcontent-length
less than zero is sentContent length should be the size of the message body (not including headers). This would include POST data (presumably how your authToken is sent) sent with the request.
The length sent shouldn't need to be exact (though you should try!). Most browsers don't care about the length (as long as it is greater than the actual content length). If it is less than the actual content length, most browsers choke, but not the other way around. I'm assuming Google's servers will act similarly.
所以,解决方案似乎是
a) 第二个请求是 GET 而不是 POST
和
b) 我传入的用户名需要完全限定的电子邮件地址 ([email protected],不仅仅是嘘)
So, the solution appears to be that
a) the second request is a GET not a POST
and
b) the username I was passing in requires a fully qualified email ([email protected], not just boo)