我在读this,但是我不知道在什么情况下重定向请求应该有什么样的请求类型,比如函数(初始请求类型,响应类型) ->重定向请求类型。
在我的特殊情况下,我有:
Google Chrome对重定向的请求使用了GET。
在Python库requests中,有以下代码(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即,在303 (codes.see_other)的情况下,重定向请求类型是GET,在所有其他情况下,它是初始请求类型。也就是说,对于我上面的特殊情况,它将是POST,而不是Chrome。
这可能是错误的,因为我有一个网站,实际上这似乎是不正确的工作(即网站不能很好地这样做)。
正确的方式/功能是什么?
发布于 2011-11-15 23:59:34
根据RFC 2616,答案是“原始方法”。HTTPbis将对此进行修改,因为它没有反映浏览器所做的事情(遗憾的是)。
有关历史记录,请参阅http://trac.tools.ietf.org/wg/httpbis/trac/ticket/160。
发布于 2011-11-15 23:08:31
我刚刚在Chrome中搜索了相关代码,here是:
std::string ComputeMethodForRedirect(const std::string& method,
int http_status_code) {
// For 303 redirects, all request methods except HEAD are converted to GET,
// as per the latest httpbis draft. The draft also allows POST requests to
// be converted to GETs when following 301/302 redirects, for historical
// reasons. Most major browsers do this and so shall we. Both RFC 2616 and
// the httpbis draft say to prompt the user to confirm the generation of new
// requests, other than GET and HEAD requests, but IE omits these prompts and
// so shall we.
// See:
// https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3
if ((http_status_code == 303 && method != "HEAD") ||
((http_status_code == 301 || http_status_code == 302) &&
method == "POST")) {
return "GET";
}
return method;
}发布于 2011-11-15 22:57:09
除了303和307之外,根据spec,这两种行为都是可接受的,主要是由于历史原因。
https://stackoverflow.com/questions/8138137
复制相似问题