Click the blue “Programmer DD” above and select “Add to Favorites”
Reply with “Resources” to get exclusive learning materials!
Source | 8rr.co/4zhkWhether in backend or frontend development, we all encounter different HTTP status codes. Some common status codes include:
-
200 – The server successfully returned the webpage
-
404 – The requested webpage does not exist
-
503 – Service unavailable
1xx (Informational Responses)
Indicates that the request was received and the process is continuing.
-
100 (Continue) The requester should continue with the request. The server returns this code to indicate that it has received the first part of the request and is waiting for the rest.
-
101 (Switching Protocols) The requester has asked the server to switch protocols, and the server has confirmed and is ready to switch.
2xx (Success)
Indicates that the request was successfully processed.
-
200 (OK) The server successfully processed the request. Typically, this means the server provided the requested webpage.
-
201 (Created) The request was successful, and the server created a new resource.
-
202 (Accepted) The server accepted the request but has not yet processed it.
-
203 (Non-Authoritative Information) The server successfully processed the request, but the returned information may come from another source.
-
204 (No Content) The server successfully processed the request but did not return any content.
-
205 (Reset Content) The server successfully processed the request but did not return any content.
-
206 (Partial Content) The server successfully processed part of the GET request.
3xx (Redirection)
Indicates that further action is needed to complete the request. These status codes are typically used for redirection.
-
300 (Multiple Choices) The server can perform multiple operations for the request. The server can choose one operation based on the requester (user agent) or provide a list of operations for the requester to choose from.
-
301 (Moved Permanently) The requested webpage has been permanently moved to a new location. When the server returns this response (in response to a GET or HEAD request), it automatically redirects the requester to the new location.
-
302 (Found) The server is currently responding to the request from a different location, but the requester should continue to use the original location for future requests.
-
303 (See Other) The requester should use a separate GET request to retrieve the response from a different location when the server returns this code.
-
304 (Not Modified) The requested webpage has not been modified since the last request. When the server returns this response, it does not return the webpage content.
-
305 (Use Proxy) The requester can only access the requested webpage through a proxy. If the server returns this response, it also indicates that the requester should use the proxy.
-
307 (Temporary Redirect) The server is currently responding to the request from a different location, but the requester should continue to use the original location for future requests.
4xx (Client Errors)
These status codes indicate that there may be an error with the request, preventing the server from processing it.
-
400 (Bad Request) The server does not understand the syntax of the request.
-
401 (Unauthorized) The request requires authentication. The server may return this response for webpages that require login.
-
403 (Forbidden) The server refuses the request.
-
404 (Not Found) The server cannot find the requested webpage.
-
405 (Method Not Allowed) The method specified in the request is not allowed.
-
406 (Not Acceptable) The requested webpage cannot respond with the content characteristics requested.
-
407 (Proxy Authentication Required) This status code is similar to 401 (Unauthorized) but specifies that the requester should authorize the use of a proxy.
-
408 (Request Timeout) The server timed out waiting for the request.
-
409 (Conflict) The server encountered a conflict while processing the request. The server must include information about the conflict in the response.
-
410 (Gone) The server will return this response if the requested resource has been permanently deleted.
-
411 (Length Required) The server does not accept requests without a valid Content-Length header field.
-
412 (Precondition Failed) The server did not meet one of the preconditions set by the requester in the request.
-
413 (Payload Too Large) The server cannot process the request because the payload is too large, exceeding the server’s processing capacity.
-
414 (URI Too Long) The requested URI (usually a URL) is too long for the server to process.
-
415 (Unsupported Media Type) The format of the request is not supported by the requested page.
-
416 (Range Not Satisfiable) The server will return this status code if it cannot provide the requested range.
-
417 (Expectation Failed) The server did not meet the requirements of the “Expect” request header field.
5xx (Server Errors)
These status codes indicate that the server encountered an internal error while trying to process the request. These errors may be due to issues with the server itself, rather than errors in the request.
-
500 (Internal Server Error) The server encountered an error and could not complete the request.
-
501 (Not Implemented) The server does not have the capability to fulfill the request. For example, this code may be returned when the server does not recognize the request method.
-
502 (Bad Gateway) The server received an invalid response from an upstream server while acting as a gateway or proxy.
-
503 (Service Unavailable) The server is currently unable to handle the request (due to overload or maintenance). Typically, this is just a temporary status.
-
504 (Gateway Timeout) The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
-
505 (HTTP Version Not Supported) The server does not support the HTTP protocol version used in the request.
RFC 6585 introduces four new HTTP status codes.
Is the HTTP protocol still evolving? Yes, the HTTP protocol has been evolving, and the new status codes are very useful for developing REST services or HTTP-based services. Below, we detail these four new status codes and whether they should be used.
428 Precondition Required Preconditions are conditions that must be met for a request to succeed when the client sends an HTTP request.
A good example is the If-None-Match header, which is often used in GET requests. If If-None-Match is specified, the client will only receive a response if the ETag in the response changes.
Another example of a precondition is the If-Match header, which is generally used in PUT requests to indicate that only unchanged resources should be updated. This helps prevent clients from overwriting each other’s changes when multiple clients are using the HTTP service.
When the server uses the 428 Precondition Required status code, it indicates that the client must send the aforementioned request headers to execute the request. This method provides the server with an effective way to prevent the ‘lost update’ problem.
429 Too Many Requests This status code is useful when you need to limit the number of requests a client can make to a service, essentially rate limiting.
Previously, there were some similar status codes, such as ‘509 Bandwidth Limit Exceeded’. Twitter uses 420 (which is not an HTTP-defined status code).
If you want to limit the number of requests a client can make to a service, you can use the 429 status code, along with a Retry-After response header to inform the client how long to wait before making another request.
431 Request Header Fields Too Large In some cases, the HTTP request headers sent by the client can become very large, and the server can send a 431 Request Header Fields Too Large to indicate this issue.
511 Network Authentication Required This status code is interesting to me. If you are developing an HTTP server, you may not need to handle this status code, but if you are writing an HTTP client, this status code is very important.
If you frequently use laptops and smartphones, you may notice that many public Wi-Fi services require you to accept some terms or log in before you can use them. This is done by intercepting HTTP traffic, where the network returns a redirect and login page when the user tries to access the network. This can be annoying, but it is the reality. Using these “intercepting” clients can have some annoying side effects. Two examples mentioned in the RFC are:
If you access a website before logging into Wi-Fi, the network device will intercept the first request, and these devices often have their own website icon ‘favicon.ico’. After logging in, you may find that the website icon you accessed for a while is the Wi-Fi login page’s icon.
If the client uses an HTTP request to look for a document (possibly JSON), the network will respond with a login page, causing your client to parse incorrectly and leading to client runtime exceptions. This issue is very common in practice.
Therefore, the introduction of the 511 status code is to address this issue.
If you are writing an HTTP client, it is best to check for the 511 status code to confirm whether authentication is required before accessing.
Original article in English: http://www.rooftopsolutions.nl/blog/new-http-status-codes
Previous recommendations
Huawei: 0 yuan + 3 months = Full Stack Frontend Engineer
Why is Nginx so fast that it can’t stop?
IntelliJ IDEA 2020.2 EAP 5 Released: Perfect support for Java 15
Let’s talk about thread safety in Spring
Those practical and aesthetically pleasing desktops!
Scan to follow me
Learn together, progress together