This is the 12th day of my participation in Gwen Challenge
preface
The first step is to determine where the status code is, which is in the status line in the response header of the response message.
Curl -i + url to retrieve the response header
curl -I https://www.anblog.top
Copy the code
The state row is the blue part
It consists of three parts
Version: indicates the Http Version, usually Http /1.1
Status Code: is the Status Code of the main character, which is 200 in the figure
Reason: Some brief descriptions of status codes, for example, 200 is OK, 301 is Moved Permanently, 404 is not found, etc. (Currently most clients ignore it)
The RFC standard classifies status codes into five types. The actual range of status codes ranges from 100 to 599.
What is the RFC
It’s almost universally accepted as a standard for the Internet.
Status code
Represents the result of the server’s processing of the request in code.
Description of the five TYPES of HTTP status codes
- 1xx: indicates a warning message. It is in the intermediate state of protocol processing and requires subsequent operations
- 2xx: Yes, the packet is received and processed correctly
- 3xx: redirects. The resource location changes and the client needs to resend the request
- 4xx: An error occurs on the client. The request packet is incorrect, and the server cannot process it
- 5xx: Server error. An internal error occurred while the server was processing the request
1xx
101-switching Protocols: The client uses the Upgrade header field to request that the HTTP protocol be changed to another protocol to continue communication, such as WebSocket. If the server also agrees to change the protocol, status code 101 is sent, and subsequent data transfers do not use HTTP.
2xx
200 OK: indicates that everything is fine and the server returns the result as expected, usually with the body data after the response header.
204 No Content: Has the same meaning as 200, except that there is No body data after the response header.
The server handles the request, but the data in the body is not the entire resource, it is part of it. (the 206 status code also has a header field, content-range, which indicates the Range of the body data used to confirm with the client. For example, content-range :bytes 0-99/2000, which indicates that the first 100 bytes of the 2000 data are retrieved.)
3xx
301 Moved Permanently: Redirects Permanently. The requested resource no longer exists, and you need to access it again using a new URI.
302 Found: Temporary redirection, indicating that the requested resource is still there but needs to be accessed with another URI for the time being.
304 Not Modified: If the cache has expired, an if-none-match value is added to the HTTP request header and compared with the eTAG value of the last request header. If the value is the same, the cache content has Not changed, and 304 is returned.
301 302 Application scenarios
When a website or page temporarily moves to a new location within 24-48 hours, it is necessary to jump to 302. For example, I have a house, but I recently went to a relative’s house, and I returned it in two days. The scenario of using 301 redirect is that the previous website needs to be removed for some reason, and then it needs to be accessed to a new address, which is permanent. For example, your house is actually rented, and now the lease term expires, you find a house in another place, and the house you rented before is no longer living.
301 is used to redirect HTTPS, so that visitors can only go to your HTTPS page. For example, if you type http://www.anblog.top, the server will redirect you to https://www.anblog.top.
4xx
400 Bad Request: indicates a common error code. The Request packet contains an error, but the error is very general. Therefore, avoid such a general status code when developing the Web.
403 Forbidden: The server forbids you to access the resource, some will write the reason in the body returned, more often nothing, just a 403.
404 Not Found: The source was Not Found on the server, so it could Not be sent to the client.
405 Method Not Allowed: Certain methods are Not Allowed to operate resources. For example, POST is Not Allowed. Only GET is Allowed.
406 Not Acceptable: The resource does Not meet the requirements of the client request, for example, the request is in Chinese but English only;
408 Request Timeout: The server waits too long for the Request Timeout.
409 Conflict: Multiple requests are in Conflict, which can be understood as a race when multiple threads are concurrent;
413 Request Entity Too Large: The body in the Request packet is Too Large.
414 request-uri Too Long: The URI in the Request line is Too large.
429 Too Many Requests: The client sent Too Many Requests, usually due to the server’s connection restriction policy;
431 Request Header Fields Too Large: A field or the total size of the Request Header is Too Large.
5xx
5XX Status code Indicates that the client requests the packet correctly, but the server fails to return the response data due to an internal error during processing. The status code is an error code on the server.
“500 Internal Server Error” is a common Error code similar to 400. We do not know what Error occurred on the Server. This should be a good thing for the server, however, as it is generally not desirable to share internal server details, such as the faulty function call stack. Although not conducive to debugging, but can prevent hackers from snooping or analysis.
501 Not Implemented indicates that the functionality requested by the client is Not yet supported and may be supported in the future, but it is Not known when.
502 Bad Gateway is usually an error code returned when the server functions as a Gateway or proxy, indicating that the server works properly but an error occurs when accessing the back-end server. The specific cause of the error is unknown.
503 Service Unavailable indicates that the server is busy and cannot respond to services temporarily. When we go online, the message “The network Service is busy. Please try again later” is the status code 503. 503 is a “temporary” state, and the server will probably become less busy After a few seconds, so the 503 response usually has a retry-after field indicating how soon the client can try to send the request again.
conclusion
-
In Web development, explicit status codes are as explicit as possible.
-
The best way to receive an error code is to have a popover or page representing the MSG field in the RETURNED BODY JSON data.