当前位置:网站首页>Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes

Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes

2022-07-05 21:40:00 51CTO

1、 The status code tells the result of the request returned from the server

The responsibility of the status code is when the client sends a request to the server , Describe the result of the returned request . With the help of the status code , The user can know that the server is processing the request normally , There are still mistakes .

Category reason
1XXInformational( Informational status code ) Accept request processing
2XXSuccess( Success status code ) The request is processed normally
3XXRedirection( Redirect the status code ) Additional operations are required to complete the request
4XXClient Error( Client error status code ) The server was unable to process the request
5XXServer Error( Server error status code ) Server processing request error

1.1、2XX success

2xx The result of the response shows that the request was processed normally .

1.1.1、200 OK

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ Status code
Indicates that the request sent from the client is normally processed in the server . In the response message , The information returned with the status code will change according to different methods . such as :

  • Use GET When the method is used , The entity corresponding to the request resource is returned as a response ;
  • Use HEAD When the method is used , The entity header corresponding to the request resource does not return with the message body as a response ( That is, only the header is returned in the response , The body of the entity is not returned ).

1.1.2、204 No Content

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ Status code _02
The status code represents that the request received by the server has been successfully processed , But the main body of the entity is not included in the returned response message . in addition , Nor is it allowed to return the body of any entity . such as : After request processing from browser , return 204 Respond to , Then the page displayed by the browser will not be updated . Generally, you only need to send information from the client to the server , The client does not need to send new information content to use .

1.1.3、206 Partial Content

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ Status code _03
The status code indicates that the client has made a range request , And the server successfully executed this part of GET request . The response message contains the message from Content-Range Specify the scope of entity content .

1.2、3XX Redirect

3XX The response results show that the browser responds to perform some special processing to correctly process the request .

1.2.1、301 Moved Permanently

Permanent redirection . Changing the status code indicates that the requested resource is allocated to a new URI, In the future, we should use what resources refer to now URI. in other words , If you have mapped resources to URI Saved as bookmark , At this time, we should follow location The first field prompts URI Save again .

1.2.2、302 Found

Temporary redirection . This status code indicates that the requested resource has been allocated a new URI, Hope users ( This time ) Can use the new URI visit . This status code and 301 Moved Permanently The status code is similar , but 302 The resource represented by the status code of is not permanently moved , This is temporary , If the corresponding resource has been moved URI There is a possibility of change in the future . Let's say the user puts URI Bookmark saved , But not like 301 Update the bookmark as the status code appears , But still keep the returned 302 Status code page URI For Bookmarks .

1.2.3、303 See Other

The status code indicates that there is another URI, You should use GET Method to get the requested resource .303 Status codes and 302 The status code has the same function , however 303 The status code clearly indicates that the client should adopt GET Method to get resources , With this 302 The status code is different . such as , When using POST Method access CGI Program , The processing result after its execution is that the client can use GET Method to redirect to another URI On the way up , return 303 Status code . although 302 Found Status codes can also achieve the same function , But here we use 303 The status code is ideal .
When 301、302、303 When the response status code returns , Almost all browsers will put POST Change to GET, And delete the main body in the request message , Then the request will be sent again automatically .
301、302 The standard is to prohibit POST The method is changed to GET Methodical , But in practice, people do it .

1.2.4、304 Not Modified

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ client _04
The status code indicates that when the client sends a conditional request , The server side allows requests to access resources , But after the request fails to meet the conditions , direct
return 304 Not Modified( Server side resources have not changed , You can use the client's unexpired cache directly ).304 When the status code returns , Does not contain the body part of any response .304 Although it is classified as 3XX In category , But it has nothing to do with redirection .

1.2.5、307 Temporary Redirect

Temporary redirection . The status code and 302 Found It has the same meaning . Even though 302 Standard prohibition POST Transform into GET, But in practice, we do not abide by .307 Will follow browser standards , Not from POST become GET. however , For the behavior of processing responses , Each browser may have a different situation .

1.3、4XX Client error

4XX The result of the response shows that the client is the cause of the error .

1.3.1、400 Bad Request

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ Status code _05
This status code indicates that there is a syntax error in the request message , When a mistake happens , You need to modify the content of the request and send the request again . in addition , Browsers will look like 200 OK Treat the status code as well .

1.3.2、401 Unauthorized

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ The server _06
This status code indicates that the sent request needs HTTP authentication (BASIC authentication 、DIGEST authentication ) Authentication information . In addition, if it has been done before 1 Requests , It means that the user authentication fails .
Return contains 401 The response to must contain a... For the requested resource WWW-Authenticate The first one is for questioning (challenge) User information . When the browser first receives 401 Respond to , The dialog window for authentication will pop up .

1.3.3、403 Forbidden

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ The server _07
This status code indicates that access to the requested resource has been denied by the server . There is no need for the server to give a detailed reason for rejection , But if you want to explain , The reason can be described in the main part of the entity , So that users can see . Unauthorized access to the file system , There's something wrong with access rights ( Never authorized source IP Address trying to access ) It's possible that 403 Why .

1.3.4、404 Not Found

This status code indicates that the requested resource cannot be found on the server or the server cannot respond without knowing the reason , besides , It can also be used when the server rejects the request and does not want to explain the reason .

1.4、5XX Server error

1.4.1、500 Internal Server Error

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ The server _08
The status code indicates that an error occurred on the server side while executing the request . It could be Web Applications exist bug Or some temporary failure .

1.4.2、503 Service Unavailable

 Summary appears 2xx、3xx、4xx、5xx The reason for the status code _ Status code _09
The status code indicates that the server is temporarily overloaded or under shutdown maintenance , Can't process the request right now . If you know in advance how long it will take to get rid of the above situation , Best write Retry-After The first field is returned to the client .

1.4.3、504 Gateway Timeout

This status code indicates that the server-side gateway timed out , Unable to process user request .
Be careful : Sometimes the returned status code is not necessarily correct , This user sometimes cannot detect , such as Web An error occurred inside the application , The status code still returns 200 OK, This kind of situation is often encountered .

原网站

版权声明
本文为[51CTO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207052133111158.html