http有状态和无状态_HTTP状态代码列表

http有状态和无状态

An HTTP status code is the first line in an HTTP response, that’s sent from a server to the client.

HTTP状态代码是HTTP响应中的第一行,它是从服务器发送到客户端的。

This list will be useful if you are trying to find out why a server sent a particular status code, and see what does it mean, or if you are building the server and you are browsing for the perfect status code to return.

如果您试图找出服务器为什么发送特定状态代码,并查看其含义,或者正在构建服务器并且正在浏览返回的理想状态代码,此列表将非常有用。

Status codes are expressed through 3-digit numbers, plus a short description.

状态代码由3位数字和简短说明表示。

The first digit of the number identifies the response group.

数字的第一位标识响应组

There are 5 groups:

有5组:

  • 1xx: informational response - indicates that the request was received and understood

    1xx :信息响应-表示已收到并理解了请求

  • 2xx: successful response - indicates the action requested by the client was received, understood and accepted

    2xx :成功响应-表示已收到,理解并接受了客户请求的操作

  • 3xx: redirection - indicates the client must take additional action to complete the request

    3xx :重定向-表示客户端必须采取其他措施才能完成请求

  • 4xx: client error - indicates there was an error, that seems to have been caused by the client

    4xx :客户端错误-表示存在错误,似乎是由客户端引起的

  • 5xx: server error - indicates that an error happened on the server

    5xx :服务器错误-表示服务器上发生了错误

In the rest of the post I list all the useful status codes.

在其余的文章中,我列出了所有有用的状态代码。

(I removed some technology-specific ones, like the WebDAV ones, and the ones very rarely used)

(我删除了一些技术特定的技术,例如WebDAV以及很少使用的技术)

信息回应 (Informational responses)

Status codeDescription
100 ContinueThe 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 a 100 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 response 417 Expectation Failed indicates that the request should be repeated without the Expect header as it indicates that the server doesn’t support expectations (this is the case, for example, of HTTP/1.0 servers).
101 Switching ProtocolsThe client asked the server to switch protocols and the server has agreed to do so. See RFC 7231#6.2.2
状态码 描述
100继续 服务器已接收到请求标头,客户端应继续发送请求正文(对于需要发送正文的请求;例如POST请求)。 在因不适当的标头而拒绝了请求之后,将大型请求正文发送到服务器将效率很低。 若要使服务器检查请求的标头,客户端必须在其初始请求中发送Expect:100-continue作为标头,并在发送正文之前收到100 Continue状态码作为响应。 如果客户端收到错误代码,例如403(禁止)或405(不允许使用方法),则不应发送请求的正文。 响应417 Expectation Failed指示应重复请求而没有Expect头,因为它指示服务器不支持期望(例如,HTTP / 1.0服务器就是这种情况)。
101交换协议 客户端要求服务器切换协议,并且服务器已同意这样做。 参见RFC 7231#6.2.2

成功的回应 (Successful responses)

Status codeDescription
200 OKThis is the standard response for successful HTTP requests.
201 CreatedTypically a response to a POST request. The request has been completed, and a new resource has been created.
202 AcceptedThe request has been accepted for processing. There’s nothing said about the actual processing, and the result of that, which might happen on a separate server, or batched.
203 Non-Authoritative InformationThe original server returned a 200, and a transforming proxy between the client and the server changed the payload
204 No ContentThe server successfully processed the request, but is not returning any content.
205 Reset ContentThe server successfully processed the request, but is not returning any content. Similar to a 204 response, but the server requires that the client resets the document view (used to clear forms, for example)
206 Partial ContentIn response to a Range request coming from the client, the server sends a partial content response. See RFC 7233#4.1
状态码 描述
200 OK 这是成功的HTTP请求的标准响应。
创建了201 通常是对POST请求的响应。 该请求已完成,并且已创建新资源。
202接受 该请求已被接受以进行处理。 关于实际处理及其结果,没有任何说明,这可能发生在单独的服务器上,也可能成批处理。
203非权威信息 原始服务器返回200,客户端和服务器之间的转换代理更改了有效负载
204没有内容 服务器成功处理了该请求,但未返回任何内容。
205重设内容 服务器成功处理了请求,但未返回任何内容。 与204响应类似,但服务器要求客户端重置文档视图(例如,用于清除表单)
206部分内容 响应来自客户端的Range请求,服务器发送部分内容响应。 参见RFC 7233#4.1

重新导向 (Redirection)

Status codeDescription
301 Moved PermanentlyThis and all future requests should be directed to the given URI. Only use with GET/HEAD requests, and 308 Permanent Redirect for all the other methods.
302 FoundThe resource is temporarily moved to a URL specified by the Location header. Only use with GET/HEAD requests, and 307 Temporary Redirect for all the other methods.
303 See OtherAfter a POST or PUT request, points to the confirmation message in the Location header, accessible using a new GET request.
304 Not ModifiedWhen the client uses the request headers If-Modified-Since or If-None-Match, this response status code indicates that the resource has not been modified.
307 Temporary RedirectSimilar to the 302 request, except it does not allow changing the HTTP method
308 Permanent RedirectSimilar to the 301 request, except it does not allow changing the HTTP method
状态码 描述
301永久移动 此请求和所有将来的请求都应定向到给定的URI。 仅用于GET / HEAD请求,所有其他方法都使用308 Permanent Redirect
找到302个 资源被临时移动到Location标头指定的URL。 仅用于GET / HEAD请求,所有其他方法都使用307 Temporary Redirect
303查看其他 在POST或PUT请求之后,指向Location头中的确认消息,可以使用新的GET请求进行访问。
304未修改 当客户端使用请求标头If-Modified-SinceIf-None-Match ,此响应状态代码指示资源尚未修改。
307临时重定向 302请求类似,不同之处在于它不允许更改HTTP方法
308永久重定向 301请求类似,不同之处在于它不允许更改HTTP方法

客户错误 (Client errors)

Status codeDescription
400 Bad RequestDue to a request error that was generated on the client, the server cannot process the request. Errors can include a malformed request, size too large to be handled, or others.
401 UnauthorizedSent when authentication is required and the client is not authorized
403 ForbiddenThe resource is not available for various reasons. If the reason is authentication, prefer the 401 Unauthorized status code.
404 Not FoundThe requested resource could not be found.
405 Method Not AllowedThe resource is not available through that HTTP method, but might be with another.
406 Not AcceptableThe client passed an Accept header with values that are not compatible with the server.
407 Proxy Authentication RequiredBetween the client and the server there is a proxy that requires authentication.
408 Request TimeoutThe server timed out waiting for the request.
409 ConflictIndicates that the request could not be processed because of conflict in the current state of the resource, such as an edit conflict between multiple simultaneous updates.
410 GoneThe resource is no longer available and will not be available again. More powerful than a 404, for example search engines interpret it as an indication to remove that resource from their index.
411 Length RequiredThe client needs to add a Content-Length header to the request, and it was required.
412 Precondition FailedReturned if the client sent an If-Unmodified-Since or If-None-Match request header, and the server cannot satisfy that condition.
413 Payload Too LargeThe request is larger than the server is willing or able to process.
414 URI Too LongThe URI provided was too long for the server to process.
415 Unsupported Media TypeThe request entity has a media type which the server or resource does not support.
416 Range Not SatisfiableThe client has asked for a portion of the file using the Range header, but the server cannot supply that portion.
417 Expectation FailedThe server cannot meet the requirements of the Expect request header.
421 Misdirected RequestThe request was directed at a server that is not able to produce a response (for example because of connection reuse).
426 Upgrade RequiredThe client should switch to a different protocol such as TLS/1.0, specified in the Upgrade header field.
428 Precondition RequiredThe server requires the request to contain a If-Match header.
429 Too Many RequestsThe user has sent too many requests in a given amount of time. Used for rate limiting.
431 Request Header Fields Too LargeThe request cannot be fulfilled because one or more headers, or the whole headers set, is too large.
451 Unavailable For Legal ReasonsThe resource is not available due to legal reasons
状态码 描述
400错误的要求 由于客户端上生成了请求错误,因此服务器无法处理该请求。 错误可能包括格式错误的请求,太大而无法处理的请求或其他。
401未经授权 在需要身份验证且未授权客户端时发送
403禁止 由于各种原因,该资源不可用。 如果原因是身份验证,请使用401 Unauthorized状态码。
找不到404 找不到请求的资源。
405方法不允许 该资源无法通过该HTTP方法使用,但可能与其他资源一起使用。
406不可接受 客户端传递了一个Accept头,其值与服务器不兼容。
要求407代理身份验证 在客户端和服务器之间有一个需要身份验证的代理。
408请求超时 服务器超时等待请求。
409冲突 指示由于资源的当前状态冲突(例如多个同时更新之间的编辑冲突)而无法处理请求。
410去了 该资源不再可用,将不再可用。 例如,搜索引擎比404强大,将其解释为从其索引中删除该资源的指示。
411所需长度 客户端需要向请求添加Content-Length标头,这是必需的。
412前提条件失败 如果客户端发送了If-Unmodified-SinceIf-None-Match请求标头,并且服务器无法满足该条件,则返回该值。
413有效负载过大 该请求大于服务器愿意或能够处理的请求。
414 URI太长 提供的URI太长,服务器无法处理。
415不支持的媒体类型 请求实体具有服务器或资源不支持的媒体类型。
416范围不满足 客户端已使用Range标头要求提供文件的一部分,但服务器无法提供该部分。
417期望失败 服务器无法满足Expect请求标头的要求。
421错误的请求 该请求被定向到不能产生响应的服务器(例如,由于连接重用)。
426需要升级 客户端应切换到“ Upgrade标头”字段中指定的其他协议,例如TLS / 1.0。
428需要先决条件 服务器要求该请求包含If-Match标头。
429请求过多 用户在给定的时间内发送了太多请求。 用于速率限制。
431请求标头字段太大 由于一个或多个标头或整个标头集太大,因此无法满足该请求。
451由于法律原因不可用 由于法律原因该资源不可用

服务器错误 (Server errors)

Status codeDescription
500 Internal Server ErrorA generic server error message, given when an unexpected condition was encountered and no more specific message is suitable.
501 Not ImplementedThe server either does not recognize the request method, or it lacks the ability to fulfil the request.
502 Bad GatewayThe server was acting as a gateway or proxy and received an invalid response from the upstream server.
503 Service UnavailableThe server is currently temporarily unavailable (because it is overloaded or down for maintenance).
504 Gateway TimeoutThe server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
505 HTTP Version Not SupportedThe server does not support the HTTP protocol version specified in the request.
状态码 描述
500内部服务器错误 通用服务器错误消息,在遇到意外情况且没有更多特定消息时给出。
501未实施 服务器要么无法识别请求方法,要么就无法满足请求。
502错误的网关 该服务器充当网关或代理,并从上游服务器收到无效响应。
503服务不可用 该服务器当前暂时不可用(因为它过载或为了维护而关闭)。
504网关超时 该服务器充当网关或代理,没有及时收到上游服务器的响应。
不支持505 HTTP版本 服务器不支持请求中指定的HTTP协议版本。

翻译自: https://flaviocopes.com/http-status-codes/

http有状态和无状态

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值