As web developers, we deal with status codes like 200, 304, 404, 501, etc. What do they mean? Today, let’s talk about ~
What is an HTTP status code
The HTTP status code is a 3-digit code that the server returns to the client (because this is web development, and the client refers to the browser client).
These status codes correspond to the message of the conversation between the browser and the server. They communicate with each other whether things in between worked or failed or something else happened (e.g., Continue). Knowing the status code can help you diagnose errors quickly, reduce downtime on your site, and more.
Status code classification
Status codes are classified into five types, starting with 1-5 digits, as follows:
- 1XXS – Informational: The server is processing the request.
- 2XXS – Success message: The request has been completed and the server has provided the expected response to the browser.
- 3XXs – Redirect: Your request is redirected elsewhere. The server received the request, but there was some kind of redirect.
- 4XXs – Client error: An error occurred on the client, causing the server to be unable to process the request.
- 5XXS – Server error: The client issued a valid request, but the server failed to process the request correctly.
Note: 304 in class 3xxs is an anomaly and does not belong to the redirection message prompt, which will be covered later
HTTP status code general content has been understood, but in the specific work, to use the specific status code, we will expand the following description of some of their status code and work often used those status code 🐱
1 XXS status code
- 100 Continue: Indicates that all of the requested content is valid so far, and the client should Continue the request and, if complete, ignore it.
- 101 Switching Protocol: The status code is the responding client
Upgrade
It is sent and indicates that the server is also switching protocols. - 103 Early Hints: Mainly used with
Link
The link header is used together to allow the user agent to start preloading resources while the server is still preparing the response.
Note: In web development work, we all use a wrapped library for interface requests, and the browser console network does not appear this type of status code prompt (I have not seen 😢), so this category is basically not touched, learn about it.
2 XXS status code
- 200 OK: The request succeeded. The meaning of success depends on the HTTP method:
GET
: The resource has been extracted and transmitted in the message body.HEAD
The: entity header is in the message body.POST
: The resource describing the result of the action is transferred in the message body.TRACE
: Message body contains the request information received by the server. (Method is not safe, generally not used)
Speaking of HTTP methods, poke HTTP request methods in this parsing tutorial.
- 201 Created: The request was successful and a new resource was created as a result. This is usually done in
PUT
orPOST
The response sent after the request. - 202 Accepted: Request received, but no response, no result. This means that there is no asynchronous response to indicate the result of the current request, and that other processes and services are expected to handle the request, or batch processing.
- 204 No Content: The server successfully processed the request, but does not need to return any physical content and wants to return updated meta-information. encounter
Complex request
The browser will send oneOPTION
Method to preprocess and return the response.
For complex and simple requests, see this article CORS Non-simple requests.
- 205 Reset Content: The server successfully processed the request, but did not return anything. Unlike the 204 response, the response that returns this status code requires the requester to reset the document view.
Note: The most commonly used 2XXS status codes are 200 and 204. When encountering the 204 status code, pay attention to whether the request you send is a complex request. If it is a complex request, does the browser accept the request when 204 is returned? If not, ask the backend to configure the request.
3 XXS status code
As mentioned above, this category is a prompt for redirection, but there is a special quirk –304, which does not indicate a redirection message, but indicates that the resource has not been changed. As to why can be put in this classification inside, really do not know ~ (see the officer to know the words of the supplement below) 👏
- 301 Moved Permanently: The requested resource has been
permanent
Move to a new location, and any future references to this resource should use one of the several URIs returned by the response. - 302 Found(Previously “Moved temporarily”): Requested resource now
temporary
Respond to requests from different URIs. Since such redirects are temporary, the client should continue to send future requests to the original address. Only in theCache-Control
orExpires
The response is cacheable only if specified in. - 303 See Other: The response to the current request can be found at another URI and should be adopted by the client
GET
To access that link. This method exists primarily to allow the output of POST requests activated by the script to be redirected to a new resource. - 304 Not Modified: The server should return this status code if the client sends a conditional GET request and the request is allowed, and the content of the document has not changed (since the last access or according to the conditions of the request). The 304 response disallows the inclusion of a message body and therefore always ends with the first blank line after the message header. When requested, it is generally combined
If-Modified-Since
Head use. - 307 Temporary Redirect: 307 means 302 as above. Unlike 302 in history
The request method is not allowed to change when the original request is reissued
. For example, a POST request should always be a POST request.
Note: 307 and 303 have replaced the historical 302 status code, now you see the status code 307 for temporary redirection. Details can be found on Wikipedia.
4 XXS status code
- 401 Unauthorized: This means that your login credentials are invalid. The server does not know who you are, and you need to try to log in again.
- 403 Forbidden: The server understands the request but refuses to execute it. Unlike 401, 403 knows you’re logged in, but still rejects you.
- 404 Not Found: The requested resource was Not Found on the server.
- 410 Gone: The requested resource is no longer available on the server and does not have any known forwarding address.
- 422 Unprocessable Entity: The request is well formed, but is not worth following due to semantic errors. This time to check their own parameter format semantics are correct.
- 429 Too Many Requests: The user sent Too Many Requests in a given amount of time (” limiting request rate “). This can be used in DDOS attacks.
Note: what should be noted here is 422, do not ask for link error, fart fart looking for the back end, first check the back end to the API document, to pass the field is accurate to follow up. 😂
5 XXS status code
- 500 Internal Server Error: The Server encounters an Internal Error that the Server does not know how to handle. For example, the back end students wrote the wrong model ~
- 503 Service Unavailable: The server is not ready to process the request. The common reason is that the server is down for maintenance or heavy loading.
- 504 Gateway Timeout: Indicates that the Gateway times out and the server fails to respond quickly. Request interface return pedding time too long is basically this problem, 囧.
Note: If you encounter this kind of problem, ask the backend students. Tone better, after all, everyone is for life 😄
After the mood
That’s it for today. Well, by the way, browser support for this is very good. For more details, you can directly poke my reference below. In daily Web work, understand HTTP status code is a necessary work, at least in the case of error, know where the browser and server communication barriers ~
reference
- HTTP Status Codes
- HTTP Explained: The HTTP Request Status Code Guide (Complete)
- HTTP response code
note
-
First article: github.com/reng99/blog…
-
More: github.com/reng99/blog…