This chapter describes how HTTP status codes work

The status code is responsible for describing the returned request results when the client sends a request to the server. Using the status code, we can know whether the request was properly processed on the server side.

Status codes can be divided into five types from the above:

category The reason the phrase
1XX Informational (Informational status code) The accepted request is being processed
2XX Success (Success Status code) The request is successfully processed
3XX Redirection (Redirection status code) Additional action is required to complete the request
4XX Client Error (Client Error status code) The server cannot process the request
5XX Server Error (Server Error status code) The server failed to process the request

Here are some commonly used status codes.

1. 2XX is successful

1.1 200 OK

Indicates that the request sent from the client is processed by the server.

1.2 204 No Content

This status code indicates that the request sent by the client is normally processed by the server, but no content is returned. The response packet does not contain the body part of the entity.

Generally used when only information needs to be sent from the client to the server, but the server does not need to send content to the client.

1.3 206 Partial Content

The status code indicates that the client made a range request and the server performed that part of the GET request. The response message contains the entity Content in the Range specified by content-range.

2. 3XX redirect

The 3XX response status code indicates that the browser needs to perform some special processing to properly process the request.

2.1 301 version Permanently

Permanent redirect.

This status code indicates that the requested resource has been assigned a new URI and that the URI specified by the resource should be used later. The new URI is specified in the Location header field in the HTTP response header.

2.2 302 Found

Temporary redirect.

This status code indicates that the requested resource has been assigned a new URI and that the user is expected to access the resource using the new URI.

This is similar to the 302 Moved Permanently, but the resource 302 represents is not Permanently redirected, but only temporarily.

2.3 303 See Other

This status code indicates that because another URI exists for the requested resource, the GET method should be used to GET the requested resource.

The 303 status code has similar functionality to the 302 Found status code, but the 303 status code explicitly states that the client should use the GET method to obtain the resource.

When the 301, 302, and 303 response status codes return, almost all browsers change POST to GET and remove the body of the request message, and the request is automatically sent again.

Standards 301 and 302 forbid changing POST methods to GET methods, but in practice everyone does.

2.4 304 Not Modified

This status code indicates that when a client sends a conditional request (GET request contains if-match, if-modified-since, if-none-match, if-range, or if-unmodified-since), the server allows the request to access the resource. But because the request does Not meet the criteria, a 304 Not Modified redirection occurs, directly using the resource cached by the client.

2.5 307 Temporary Redirect

Temporary redirect.

This status code has the same meaning as 302 Found, and although the 302 standard forbids POST from becoming GET, it does so in practice.

– 307 will comply with browser standards and will not change from POST to GET. However, the behavior of handling requests varies from browser to browser.

3. 4XX client error

The results of 4XX show that the client is the cause of the error.

3.1 400 Bad Request

The status code indicates that a syntax error exists in the request packet. When an error occurs, you need to modify the content of the request and send the request again.

3.2 401 Unauthorized

The status code indicates that the request needs to be authenticated.

3.3 403 Forbidden

This status code indicates that the access to the requested resource is denied by the server. The server does not need to give a detailed reason, but it can be explained in the body of the response packet entity.

3.4 404 Not Found

This status code indicates that the requested resource could not be found on the server.

4. 5XX server error

The 5XX response results indicate that the server itself has an error.

4.1 500 Internet Server Error

This status code indicates that there is an error in the server’s execution of the request, which may be a bug in the Web application or some temporary fault.

4.2 503 Service Unavailable

This status code indicates that the server is temporarily overloaded or is down for maintenance and is unable to process requests at this time.