HTTP (4): status code


The status code consists of three digits and a reason phrase. The first digit specifies the response category, and the last two digits have no classification.

HTTP (4): status code

There are 40 kinds of HTTP status codes only recorded on rfc2616. In fact, there are 14 commonly used ones.

200 OK

Indicates that the request from the client has been processed normally on the server.

204 No Content

It indicates that the request accepted by the server has been successfully processed, but the returned response message does not contain the main body of the entity. In addition, it is not allowed to return the body of any entity. For example, when the request from the browser is processed and 204 response is returned, the page displayed by the browser will not be updated.

Scenario: it is used in the case that the client only needs to send messages to the server, and the server does not need to send new information.

206 Partial Content

Indicates that the client made a range request and the server successfully executed this part of the get request. The response message contains the entity content in the range specified by content range.

301 Moved Permanently

Permanent redirection. The status code indicates that the requested resource has been assigned a new URI, and the current URI of the resource should be used in the future. It’s time to update the address of the bookmark saved by the browser.

When you forget to add a slash ‘/’ at the end of the specified resource path, 301 redirection will be generated.

302 Found

Temporary redirection. Indicates that the requested resource has been assigned a new URI, and users are expected to access it (this time).

303 See Other

It indicates that there is another URI for the resource corresponding to the request, and the get method should be used to obtain the requested resource directionally.

303 status code and 302 status code have the same function, but 303 clearly indicates that the client should use the get method to obtain resources, which is different from 302 status code.

When 301, 302 and 303 response status codes return, almost all browsers will change post to get and delete the main body of the request message, and then the request will be sent again automatically.

It is forbidden to change the post method to get method in 301 and 302 standards, but in actual use, everyone does so.

304 Not Modified

When the client sends a conditional request, the server allows the request to access the resource, but the condition is not met. When the 304 status code returns, it does not contain any main part of the response. Although 304 is classified in 3xx category, it has nothing to do with redirection.

307 Temporary Redirect

Temporary redirection, the same as 302, will follow the browser standard and will not change from post to get.

400 Bad Request

It indicates that there is a syntax error in the request message. You need to modify the content and send it again. In addition, the browser will treat the status code like 200 OK. I didn’t understand the last sentence

401 Unauthorized

Indicates that the request requires authentication information that has passed HTTP authentication (basic authentication, dig authentication). If a request has been made before, the authentication has failed. When the browser receives 401 for the first time, a dialog window for authentication will pop up.

403 Forbidden

Indicates that access to the requested resource has been denied by the server.

404 Not Found

The requested resource could not be found on the server. It can also be used when the server rejects the request and does not want to give a reason.

500 Internal Server Error

Indicates that an error occurred when the server re executed the request. There may also be a bug or some temporary failure in the web application.

503 Service Unavailable

The server is temporarily overloaded or in the process of downtime maintenance and cannot process the request now. If you know in advance the time required to remove the above state, it is better to write the first field of “retry after” and return it to the client.

Some programs will be inconsistent with the status code. For example, the status code returns 200 OK, but the program has a problem.