HTTP:如果重定向请求是GET请求,POST请求会收到302? [英] HTTP: POST request receives a 302, should the redirect-request be a GET?

查看:1979
本文介绍了HTTP:如果重定向请求是GET请求,POST请求会收到302?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读这个,但我并没有真正从那里获得什么样的请求类型的重定向请求应该在什么情况下,即函数(初始请求类型,响应类型) - >重定向请求类型。



在我的情况下,我有:


  • 初始请求类型:POST

  • 响应类型:302



Google Chrome对重定向的请求使用了GET。

在Python库请求中,有以下代码(这里):

 #http:// www。 w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 
如果r.status_code是codes.see_other:
method ='GET'
else:
method = self.method

即,重定向请求类型在303( codes.see_other )的情况下,e是GET,在所有其他情况下,它是最初的请求类型。也就是说,对于我上面的特定情况,这将是POST,而不是Chrome。



这可能是错误的,因为我有一个网站,其实这似乎不是工作正确(即网站的行为不如此)。



什么是正确的方式/功能?

解决方案

根据RFC 2616,答案是原始方法。 HTTPbis将修改此内容,因为它不能反映浏览器的操作(可惜)。

请参阅http://trac.tools.ietf.org/wg/httpbis/trac/ticket/160 获取历史记录。


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?

解决方案

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.

这篇关于HTTP:如果重定向请求是GET请求,POST请求会收到302?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆