HTTP:POST 请求收到 302,重定向请求应该是 GET 吗?
我正在阅读此,但我并没有真正从那里得到什么请求- type 在什么情况下redirect-request应该有,即函数(初始request-type,response-type)->重定向请求类型。
在我的特定情况下,我有:
- 初始请求类型:POST
- 响应类型:302
Google Chrome 使用 GET 进行重定向请求。
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
if r.status_code is codes.see_other:
method = 'GET'
else:
method = self.method
即,在 303 的情况下,重定向请求类型为 GET (codes.see_other
),在所有其他情况下它是初始请求类型。即,对于我上面的特定情况,它将是 POST,与 Chrome 不同。
这可能是错误的,因为我有一个网站,但实际上似乎无法正常工作(即该网站以这种方式表现不佳)。
正确的方法/功能是什么?
I was reading this but I didn't really got from there what request-type the redirect-request should have in what case, i.e. the function (initial request-type, response-type) -> redirect-request-type.
In my particular case, I had:
- initial request-type: POST
- response-type: 302
Google Chrome used a GET for the redirected request.
In the Python library requests, there is the following code (here):
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4
if r.status_code is codes.see_other:
method = 'GET'
else:
method = self.method
I.e., the redirect-request-type is GET in case of 303 (codes.see_other
), in all other cases it is the initial request-type. I.e., for my particular case above, it would be POST, in contrast to Chrome.
This is probably wrong because I have one website where this actually doesn't seem to work correct (i.e. the website doesn't behave well this way).
What would be the correct way/function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚在Chrome中搜索了相关代码,这里< /a> 它是:
I just searched for the relevant code in Chrome, and here it is:
根据 RFC 2616,答案是“原始方法”。 HTTPbis 将对此进行修改,因为它不反映浏览器的功能(遗憾的是)。
请参阅http://trac.tools.ietf.org/wg/httpbis/trac/ticket/160 的历史记录。
Per RFC 2616, the answer is "the original method". HTTPbis will revise this, as it doesn't reflect what browsers do (sadly).
See http://trac.tools.ietf.org/wg/httpbis/trac/ticket/160 for the history.
除了 303 和 307 之外,根据 spec,主要是历史原因。
Except for 303 and 307, either behaviour is acceptable as per the spec, mainly for historical reasons.
在使用 Chrome 和节点请求体验之后,我思考了这个问题的答案是什么,并最初假设这是完全正常的。然后我想,虽然它可能是“历史的”,但它可能不是“正确的”。所以我找到了这个页面,听起来“正确”并不比与“历史”实现兼容重要......这听起来令人失望一分钟。然后我想起我见过的每个“传统”、非 Ajax/API、基于表单的“POST”都会以假定为 GET 的重定向进行响应。
它就是这样,并且可能永远不会改变。感谢之前所有回复者提供的所有相关信息。
I thought about what the answer to this question was after experiencing it with Chrome and node-requests, and initially assuming that it was totally normal. Then I thought that while it may be "historical", it wasn't probably "correct". So I found this page, and it sounds like being "correct" is less important than being compatible with "historical" implementations...which sounded disappointing for a minute. Then I remembered that every "traditional", non-Ajax/API, form based "POST" I have ever seen responds with a redirect that assumes a GET.
It is what it is and that's probably not changing ever. Thanks to all the previous responders for providing all the relevant info.