About http1.1 newly added status code 303, 307 and 302 comparison

               

      When HTTP1.0 introduced 302, it said that if the client sends a POST request and receives a 302 status code from the server, it cannot automatically send a repeat request to the new URI, and must confirm with the user whether it should be re-sent, because the second time At the time of POST, the environment may have changed (well, the POST method is not idempotent), and the POST operation will not meet the user's expectations. However, many browsers (user agent I describe as browsers for convenience) will turn POST requests into GET requests in this case.

      When HTTP1.1 introduced 302, it said that if the client sends a non-GET, HEAD request and receives a 302 status code from the server, it cannot automatically send a repeat request to the new URI unless it is confirmed by the user. (again -,-) However, many browsers treat 302 as 303 (note that 303 was only added in HTTP1.1, in fact, from HTTP1.0 to HTTP1.1, the browser did not move anything ), they obtain the Location field information in the header of the HTTP response message, and initiate a GET request.

      The meaning of the 302 status code of HTTP1.1 and HTTP1.0 is the same, and the browser handles it in the same way. The redirection of the POST method becomes a GET without asking the user, and this non-documentation problem still exists. Practice comes first and documentation comes after. HTTP1.1 incorporates this behavior of POST into GET into the RFC document: HTTP1.1 adds 303 and 307 status codes.

     303 and 307 are the status codes of the newly added server response documents in HTTP 1.1. They are refinements of the 302 status codes in HTTP 1.0, and are mainly used for responses to non-GET and HEAD methods. The document stipulates that the browser handles the 303 status code in the same way as the original browser handles the 302 status code of HTTP1.0; the browser handles the 307 status code in the same way as the description of 302 in the original HTTP1.0 document. 

     The existence of 303 and 307 is ultimately due to the non-idempotent nature of the POST method.
      In HTTP1.1, 302 is theoretically to be abandoned, it is refined into 303 and 307, but for compatibility, it is still widely used in the industry, and I have not encountered 303 and 307 status codes. (There is no usage scenario, and no such response message has been caught). Why is 303 and 307 less used in the industry? For the GET and HEAD methods, 307 is unnecessary, 302 or 303 can meet the requirements, and 307 is only useful for the redirection of the POST method. So I guess there are two reasons why they are rare: 1. The usage scenarios of POST method redirection are too few, making the 307 status code useless; 2. Although the GET method often requires redirection, using the 302 status code is also It works correctly, and considering the minimal compatibility issues (how can current browsers not support HTTP1.1!), there is no need to use 303.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326490063&siteId=291194637