在通过浏览器访问某个网站时,网站的响应头数据中,都会包含一个响应的状态码,如下图所示:
这种表示请求处理的状态码,一般包含两个部分:
HTTP 状态码(status code)和描述(reason-phrase)。
用于表示客户端HTTP请求的响应结果,标识服务器的处理是否处理正常状态,以及当前对应状态的简要描述。例如我们最常见的200表示响应成功,404代表找不到资源,500则是服务器异常等。
状态码的大类归纳信息总体如下:
1xx: 信息类状态(Informational)
请求到达,继续处理 (Request received, continuing process)
2xx: 成功(Success) -
请达正常处理完毕 (The action was successfully received, understood, and accepted)
3xx: 重定向(Redirection)
需要更多操作完成请求 (Further action must be taken in order to complete the request)
4xx: 客户端错误(Client Error)
请求包含语法错误或不能执行(The request contains bad syntax or cannot be fulfilled)
5xx: 服务器异常(Server Error)
服务器执行请求失败 (The server failed to fulfill an apparently valid request)
在Tomcat内部,也有一个文件用于罗列描述这些HTTP状态码,此文件位于
org.apache.catalina.valves.LocalStrings.properties,大概是下图的样子:
Tomcat内部在处理请求发送响应的时候,根据不同的情况获取对应的property,内部的实现方式一般是这个样子:
response.getWriter().write(sm.getString("http.403"))
华丽的分隔线下,则是全部HTTP状态码及简要描述,各位朋友请慢用!
长按下方二维码,关注我!
status code Description
100 Continue
101 Switching Protocols
102 Processing
103-199 Unassigned
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
207 Multi-Status
208 Already Reported
209-225 Unassigned
226 IM Used
227-299 Unassigned
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
304 Not Modified
305 Use Proxy
306 (Unused)
307 Temporary Redirect
308 Permanent Redirect
309-399 Unassigned
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Payload Too Large
414 URI Too Long
415 Unsupported Media Type
416 Range Not Satisfiable
417 Expectation Failed
418-420 Unassigned
421 Misdirected Request
422 Unprocessable Entity
423 Locked
424 Failed Dependency
425 Unassigned
426 Upgrade Required
427 Unassigned
428 Precondition Required
429 Too Many Requests
430 Unassigned
431 Request Header Fields Too Large
432-450 Unassigned
451 Unavailable for Legal Reasons
452-499 Unassigned
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported
506 Variant Also Negotiates
507 Insufficient Storage
508 Loop Detected
509 Unassigned
510 Not Extended
511 Network Authentication Required
512-599 Unassigned
各status code详细描述如下,源自tomcat内的配置文件:
http.100=The client may continue.
http.101=The server is switching protocols according to the "Upgrade" header.
http.102=The server has accepted the complete request, but has not yet completed it.
http.201=The request succeeded and a new resource has been created on the server.
http.202=This request was accepted for processing, but has not been completed.
http.203=The meta information presented by the client did not originate from the server.
http.204=The request succeeded but there is no information to return.
http.205=The client should reset the document view which caused this request to be sent.
http.206=The server has fulfilled a partial GET request for this resource.
http.207=Multiple status values have been returned.
http.208=This collection binding was already reported.
http.226=The response is a representation of the result of one or more instance-manipulations applied to the current instance.
http.300=The requested resource corresponds to any one of a set of representations, each with its own specific location.
http.301=The requested resource has moved permanently to a new location.
http.302=The requested resource has moved temporarily to a new location.
http.303=The response to this request can be found under a different URI.
http.304=The requested resource is available and has not been modified.
http.305=The requested resource must be accessed through the proxy given by the "Location" header.
http.307=The requested resource resides temporarily under a different URI.
http.308=The target resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs.
http.400=The request sent by the client was syntactically incorrect.
http.401=This request requires HTTP authentication.
http.402=Payment is required for access to this resource.
http.403=Access to the specified resource has been forbidden.
http.404=The requested resource is not available.
http.405=The specified HTTP method is not allowed for the requested resource.
http.406=The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.
http.407=The client must first authenticate itself with the proxy.
http.408=The client did not produce a request within the time that the server was prepared to wait.
http.409=The request could not be completed due to a conflict with the current state of the resource.
http.410=The requested resource is no longer available, and no forwarding address is known.
http.411=This request cannot be handled without a defined content length.
http.412=A specified precondition has failed for this request.
http.413=The request entity is larger than the server is willing or able to process.
http.414=The server refused this request because the request URI was too long.
http.415=The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
http.416=The requested byte range cannot be satisfied.
http.417=The expectation given in the "Expect" request header could not be fulfilled.
http.422=The server understood the content type and syntax of the request but was unable to process the contained instructions.
http.423=The source or destination resource of a method is locked.
http.424=The method could not be performed on the resource because the requested action depended on another action and that action failed.
http.426=The request can only be completed after a protocol upgrade.
http.428=The request is required to be conditional.
http.429=The user has sent too many requests in a given amount of time.
http.431=The server refused this request because the request header fields are too large.
http.500=The server encountered an internal error that prevented it from fulfilling this request.
http.501=The server does not support the functionality needed to fulfill this request.
http.502=This server received an invalid response from a server it consulted when acting as a proxy or gateway.
http.503=The requested service is not currently available.
http.504=The server received a timeout from an upstream server while acting as a gateway or proxy.
http.505=The server does not support the requested HTTP protocol version.
http.506=The chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
http.507=The resource does not have sufficient space to record the state of the resource after execution of this method.
http.508=The server terminated an operation because it encountered an infinite loop.
http.510=The policy for accessing the resource has not been met in the request.
http.511=The client needs to authenticate to gain network access.
status code来自:
http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml