每天背一个状态码系列
1xx Informational response
100 Continue
通俗点说的话,如果是POST 请求,我们的提交的数据超过1024 个字节,那么服务器可能不接受,那么我们可以先发一个请求,在请求头里加入 “Expect”:”100-continue”
,询问服务器是否接受,这时候如果服务器能够接收,那么我们在提交请求,而不是我们一次性直接提交数据,这样做在一定程度上减缓了服务器端的压力。
维基百科上说的
The server has received the request headers and the client should proceed to send the request body (in the case of a request for which a body needs to be sent; for example, a POST request). Sending a large request body to a server after a request has been rejected for inappropriate headers would be inefficient. To have a server check the request's headers, a client must send
Expect: 100-continue
as a header in its initial request and receive a100 Continue
status code in response before sending the body. If the client receives an error code such as 403 (Forbidden) or 405 (Method Not Allowed) then it shouldn't send the request's body. The response417 Expectation Failed
indicates that the request should be repeated without theExpect
header as it indicates that the server doesn't support expectations (this is the case, for example, of HTTP/1.0 servers).[5]
101 Switching Protocols
就是说,如果服务器发现对方在 Upgrade 中的协议,如果自己有支持更合适的,会发送 101 响应码,客户端收到后,更换协议重新访问
The requester has asked the server to switch protocols and the server has agreed to do so
2xx Successful
200 OK
通俗点说,200 表示请求成功,如果是 GET 请求,那就返回完成的数据,如果是 POST 请求,那么返回操作的执行结果
Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action
201 Created
通常来说,这个状态吗用于 PUT 请求的返回码,说的是资源已经创建,然后服务器可以将资源的地址写到响应头中的Location字段里,或者是数据里
The request has been fulfilled and resulted in a new resource being created. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by a Location header field. The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with 202 (Accepted) response instead.
A 201 response MAY contain an ETag response header field indicating the current value of the entity tag for the requested variant just created, see section
202 Accepted
与 201 不同,202返回的话是请求没有处理完成,该请求可用于异步处理的返回码
The HyperText Transfer Protocol (HTTP) 202 Accepted response status code indicates that the request has been received but not yet acted upon. It is non-committal, meaning that there is no way for the HTTP to later send an asynchronous response indicating the outcome of processing the request. It is intended for cases where another process or server handles the request, or for batch processing.
204 No Content
服务器成功响应,但是没有返回数据,客户端不应该对此做出反应,也就是说没要跳转
If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent’s active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent’s active view.
205 Reset Content
同样也是没有数据返回,但是客户端应该重置表单
The server successfully processed the request, but is not returning any content. Unlike a 204 response, this response requires that the requester reset the document view
206 Partial Content
返回部分数据,多用于下载数据,如果数据量过大,可能需要分段下载,在 Header 是以 Range 表示的
The HTTP
206 Partial Content
success status response code indicates that the request has succeeded and has the body contains the requested ranges of data, as described in theRange
header of the request.
3xx Redirect
300 Multiple Choices
多种选择,客户端收到后应该根据 Location 选择其中一个请求进行访问
The HTTP 300 Multiple Choices redirect status response code indicates that the request has more than one possible responses. The user-agent or the user should choose one of them. As there is no standardized way of choosing one of the responses, this response code is very rarely used.
301 Moved Permanently
永久移动地址,会在 Location 中附上新地址,客户端可以根据这个地址进行新的请求,通常用于 HEAD 和 POST 请求
The HyperText Transfer Protocol (HTTP)
**301 Moved Permanently**
redirect status response code indicates that the resource requested has been definitively moved to the URL given by theLocation
headers. A browser redirects to this page and search engines update their links to the resource (in 'SEO-speak', it is said that the 'link-juice' is sent to the new URL).
Even if the specification requires the method (and the body) not to be altered when the redirection is performed, not all user-agents align with it - you can still find this type of bugged software out there. It is therefore recommended to use the 301
code only as a response for GET
or HEAD
methods and to use the 308 Permanent Redirect
for POST
methods instead, as the method change is explicitly prohibited with this status.
HTTP/1.1 301 Moved Permanently
Location: http://www.example.org/index.asp
304 Not Modified
比如说一个 css 文件,客户端第二次加载时在请求头里带上 cache-control:max-age=0,以及 If-Modified-Since,如果服务器收到后,发现请求的资源没有改变,会返回一个 304,这样客户端就可以知道使用本地的缓存资源
Indicates that the resource has not been modified since the version specified by the request headers If-Modified-Since or If-None-Match. In such case, there is no need to retransmit the resource since the client still has a previously-downloaded copy.