a302
和303
response和有什么不一样?
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
这些是否可以互换,或者为什么要使用一个?您能否提供一个何时使用(而另一个不会)的用例?
lar*_*sks 39
您链接到的页面上的描述似乎很好地描述了它们的预期目的:
302 重定向表示重定向是临时的——客户端应该在以后的请求中检查原始 URL。
303 重定向旨在将POST
请求重定向到GET
资源(否则,客户端假定新位置的请求方法与原始资源的请求方法相同)。
如果您将客户端重定向为 Web 应用程序的一部分,但希望它们始终从 Web 应用程序开始(例如,URL 缩短器),则 302 重定向似乎很有意义。当您POST
从客户端接收数据(例如,表单提交)并且您希望将它们重定向到要使用GET
而不是POST
(例如,标准页面请求)检索的新网页时,可以使用303 重定向。
但是从状态代码定义中看到这个注释——大多数客户端会对 302 或 303 做同样的事情:
Note: RFC 1945 and RFC 2068 specify that the client is not allowed
to change the method on the redirected request. However, most
existing user agent implementations treat 302 as if it were a 303
response, performing a GET on the Location field-value regardless
of the original request method. The status codes 303 and 307 have
been added for servers that wish to make unambiguously clear which
kind of reaction is expected of the client.
Run Code Online (Sandbox Code Playgroud)
Lad*_*ada 22
有五种不同的重定向类型。最初只有两个(301 和 302),但大多数客户端错误地实现了它们,因此添加了三个以澄清两种不同可能行为之间的区别。
您链接到的 RFC 在 302 重定向部分对此进行了说明:
Run Code Online (Sandbox Code Playgroud)Note: RFC 1945 and RFC 2068 specify that the client is not allowed to change the method on the redirected request. However, most existing user agent implementations treat 302 as if it were a 303 response, performing a GET on the Location field-value regardless of the original request method. The status codes 303 and 307 have been added for servers that wish to make unambiguously clear which kind of reaction is expected of the client.
对于上述两种情况,后续请求应使用与原始请求相同的方法(POST、GET、CONNECT、PUT、DELETE 等),对于 GET 和 HEAD 请求以外的任何请求,客户端应提示用户在提出请求之前。
不幸的是,这是客户端有时会出错的部分,并且无论原始方法如何,它们中的大多数都会将后续请求的方法更改为 GET。因此,又创建了三个重定向代码:
现代客户端不应该对这些较新的重定向有任何问题。
归档时间: |
|
查看次数: |
25075 次 |
最近记录: |