HTTP status Code 302,303,307 of those things

Source: Internet
Author: User
Tags 303 status code

In the 3rd chapter of the HTTP authoritative guide, when explaining the 30X status code, it is completely unclear why there should be 302, 303, 307, and their relationship, a "problem in HTTP/1/1" Let me confused, inexplicable. So I've collected this resource on the Internet, mark.

First, status code--302

RFC1945 (http://tools.ietf.org/html/rfc1945#page-34), That is, HTTP1.0, when introducing 302, said that if the client sends a POST request and receives a 302 status code from the server, it cannot automatically send a duplicate request to the new URI, and must confirm with the user whether it should be re-sent, because the environment may have changed since the second post (well, the Post method is not idempotent, about idempotent before The post operation will not meet the user's expectations.    However, many browsers (the user agent I describe as a browser for ease of introduction) will turn the POST request into a GET request in this case. RFC2616 (http://tools.ietf.org/html/rfc2616#section-10.3.3), HTTP1.1, when introducing 302, says that if the client sends a non-GET, head request, it receives a 302 status code from the server , you cannot automatically send a duplicate request to the new URI unless you are confirmed by the user. (again-,-) However, many browsers treat 302 as 303 (note that 303 is HTTP1.1 just add in, in fact, from HTTP1.0 Evolution to HTTP1.1, browser nothing moved), they get to the HTTP response Message header location field information, and initiate a GET request.

Second, status code--303 and 307

From the above introduction can know, HTTP1.1 and HTTP1.0 302 status code meaning is the same, the browser to its processing is the same. The redirection of the Post method becomes get when the user is not queried, and the problem that does not conform to the document specification persists.    In practice before and after the document, HTTP1.1 the post-get behavior into the RFC document: HTTP1.1 New 303 and 307 status codes are added.    The response to the 303 status code is stated in the document, which is now the browser's handling of the 302 status code: Post redirection is get.    The 307 status code in the HTTP1.1 document is equivalent to the 302 status code in the HTTP1.0 document, and when the client's post request receives a service-side 307 status Code response, it needs to ask the user if the Post method should be initiated on the new URI, that is, 307 does not convert the post to get. From the network to find this saying "303: For a POST request, it indicates that the request has been processed, the client can then use the Get method to request the URI in the location." 307: For a POST request, the request has not been processed and the client should re-initiate the POST request to the URI in the location.    ", from the above introduction can understand that this statement is hypothetical, the document did not say, and the industry is unified so deal with, it is not good to say that I did not catch 307 and 303 of the package. The document also says that To be compatible with many HTTP1.1 browsers, the server will choose to replace the 302 status code when it needs to issue a 303 status code, whereas for 307 processing, it is necessary to include information in the response entity so that the user who cannot process the 307 status code has the ability to initiate duplicate requests in the new URI, that is, to present the redirected page to the user. Let the user go to the Point redirect Uri Link (URI is now basically URL).

Iii. Summary

303 and 307 are HTTP1.1 new server response document status code, they are HTTP1.0 in the 302 status code refinement, mainly used in the response to the non-get, head method. Documentation stipulates: The browser to the 303 status code processing with the original browser to the HTTP1.0 302 status Code processing method, the browser to the 307 status code processing and the original HTTP1.0 document in the same description of 302. The existence of 303 and 307 is, in the final analysis, caused by the non-idempotent properties of the Post method. In HTTP1.1, 302 is theoretically to be discarded, it is refined to 303 and 307, but in order to be compatible, it is still heavily used in the industry, and 303 and 307 status codes I have not met (no use of the scene, and have not caught such a response message). Why does the industry use 303 and 307 less? For the Get and head methods, 307 is not necessary, with 302 or 303 to meet the requirements, 307 is only useful in the redirection of the Post method. So I guess there are two reasons why they are rare: 1, the use of post method redirection is too few, so that 307 status code is not available, 2, the Get method is often required to use the redirect, but the use of 302 status code can also operate correctly, Consider the minimal compatibility issues (now the browser may not support HTTP1.1!).   ), there is no need to use 303. This article was reprinted from: http://www.cnblogs.com/cswuyg/p/3871976.html reference: 1, http 302 wiki http://en.wikipedia.org/wiki/HTTP_3022, RFC1945 http://tools.ietf.org/html/rfc1945#page-343, RFC2616 http://tools.ietf.org/html/rfc2616#section-10.3.3

HTTP status Code 302,303,307 of those things

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.