本来计划写一篇浏览器错误码使用的详细总结,近来想了想,第一这不是很深入的知识点、主要还是一种规定;第二对常用的几种的一个使用场景已经有所了解了,所以今天就写一个简单的汇总,并黏贴常用几个错误码的介绍在这里备查。
首先,还是说一下200和304,这两个都是关于读取缓存内容,无需服务端返回的意思。但是两者的区别在于200的cached状态是直接取缓存,304则是请求发送到后端,后端提示可以重定向到缓存。
- The request has succeeded. The meaning of a success varies depending on the HTTP method:
- GET: The resource has been fetched and is transmitted in the message body.
- HEAD: The entity headers are in the message body.
- PUT or POST: The resource describing the result of the action is transmitted in the message body.
-
TRACE: The message body contains the request message as received by the serverThis is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.其次,200不带cached就表示请求已成功完成。200系列还有多种状况,都表示已成功的不同状态,在此放几个觉得可能常用的。
- The request has succeeded. The meaning of a success varies depending on the HTTP method:
- GET: The resource has been fetched and is transmitted in the message body.
- HEAD: The entity headers are in the message body.
- PUT or POST: The resource describing the result of the action is transmitted in the message body.
-
TRACE: The message body contains the request message as received by the serverThere is no content to send for this request, but the headers may be useful. The user-agent may update its cached headers for this resource with the new ones.再次,300系列都是关于重定向的,常用的除了上述304,还有301和302,一个是地址永久重定向,一个是地址临时重定向。
- This response code means that the URI of the requested resource has been changed. Probably, the new URI would be given in the response.
- 302 Found
-
This response code means that the URI of requested resource has been changed temporarily. New changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.再次,客户端错误400系列。关于400系列的404和500系列的500/501,两者在某个情况下可能难以区分,就是在请求的资源服务器没有时候返回404,请求的method(get/post/put/head/delete))服务器不支持时显示501,其实笼统的说都有点像服务器不支持当前的这个请求,但是会把前者认为是客户端请求错误,请求了不存在的资源;后者理解为服务端对接口的方法支持的不完全。另外,对于用不支持的方法请求了不存在的资源,返回501还是404似乎并不确定,似乎可以根据自己的需求来返回对应错误码,但需要注意的是这种情况需要在错误信息中把2种错误都描述进去以提醒用户。
- The client does not have access rights to the content, i.e. they are unauthorized, so server is rejecting to give proper response. Unlike 401, the client's identity is known to the server.
- 404 Not Found
-
The server can not find requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 to hide the existence of a resource from an unauthorized client. This response code is probably the most famous one due to its frequent occurence on the web.最后,服务端错误500系列。
- The server has encountered a situation it doesn't know how to handle.
- 501 Not Implemented
-
The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD.
-