HTTP状态码

QuibblerQuibbler 2021-03-15 约 9 分钟 1758 次阅读

HTTP状态码

很多人在打开网页都遇到过404错误,网络开发中判断返回码是否等于200判定网络请求是否成功... ...这些是最常见的状态码。

参考RFC7231和状态码注册表,了解一下全部HTTP状态码。

1、五大类状态码

状态码被分为五大类:

1xx:信息性-收到请求,继续进行

2xx:成功-该动作已成功接收,理解并接受

3xx:重定向-必须采取进一步的措施才能完成请求

4xx:客户端错误-请求包含错误的语法或无法实现

5xx:服务器错误-服务器无法满足看似有效的请求

2、HTTP状态码总览

互联网数字分配机构(IANA)维护了一张最全的官方认证HTTP Code。一些字段暂未被使用,最新的状态码移步查阅:Hypertext Transfer Protocol (HTTP) Status Code Registry。

2.1、1XX Informational

[100-199] 用于指定客户端应相应的某些动作。

100Continue[RFC7231, Section 6.2.1]
101Switching Protocols[RFC7231, Section 6.2.2]
102Processing[RFC2518]
103Early Hints[RFC8297]
104-199Unassigned

2.2、2XX Success

[200-299] 用于表示请求成功。

200OK[RFC7231, Section 6.3.1]
201Created[RFC7231, Section 6.3.2]
202Accepted[RFC7231, Section 6.3.3]
203Non-Authoritative Information[RFC7231, Section 6.3.4]
204No Content[RFC7231, Section 6.3.5]
205Reset Content[RFC7231, Section 6.3.6]
206Partial Content[RFC7233, Section 4.1]
207Multi-Status[RFC4918]
208Already Reported[RFC5842]
209-225Unassigned
226IM Used[RFC3229]
227-299Unassigned

2.3、3XX Redirection

[300-399] 用于已经移动的文件并且常被包含在定位头信息中指定新的地址信息。

300Multiple Choices[RFC7231, Section 6.4.1]
301Moved Permanently[RFC7231, Section 6.4.2]
302Found[RFC7231, Section 6.4.3]
303See Other[RFC7231, Section 6.4.4]
304Not Modified[RFC7232, Section 4.1]
305Use Proxy[RFC7231, Section 6.4.5]
306(Unused)[RFC7231, Section 6.4.6]
307Temporary Redirect[RFC7231, Section 6.4.7]
308Permanent Redirect[RFC7538]
309-399Unassigned

2.4、4XX Client Error

[400-499] 用于指出客户端的错误。

400Bad Request[RFC7231, Section 6.5.1]
401Unauthorized[RFC7235, Section 3.1]
402Payment Required[RFC7231, Section 6.5.2]
403Forbidden[RFC7231, Section 6.5.3]
404Not Found[RFC7231, Section 6.5.4]
405Method Not Allowed[RFC7231, Section 6.5.5]
406Not Acceptable[RFC7231, Section 6.5.6]
407Proxy Authentication Required[RFC7235, Section 3.2]
408Request Timeout[RFC7231, Section 6.5.7]
409Conflict[RFC7231, Section 6.5.8]
410Gone[RFC7231, Section 6.5.9]
411Length Required[RFC7231, Section 6.5.10]
412Precondition Failed[RFC7232, Section 4.2][RFC8144, Section 3.2]
413Payload Too Large[RFC7231, Section 6.5.11]
414URI Too Long[RFC7231, Section 6.5.12]
415Unsupported Media Type[RFC7231, Section 6.5.13][RFC7694, Section 3]
416Range Not Satisfiable[RFC7233, Section 4.4]
417Expectation Failed[RFC7231, Section 6.5.14]
418-420Unassigned
421Misdirected Request[RFC7540, Section 9.1.2]
422Unprocessable Entity[RFC4918]
423Locked[RFC4918]
424Failed Dependency[RFC4918]
425Too Early[RFC8470]
426Upgrade Required[RFC7231, Section 6.5.15]
427Unassigned
428Precondition Required[RFC6585]
429Too Many Requests[RFC6585]
430Unassigned
431Request Header Fields Too Large[RFC6585]
432-450Unassigned
451Unavailable For Legal Reasons[RFC7725]
452-499Unassigned

2.5、5XX Server Error

[500-599] 用于支持服务器错误。

500Internal Server Error[RFC7231, Section 6.6.1]
501Not Implemented[RFC7231, Section 6.6.2]
502Bad Gateway[RFC7231, Section 6.6.3]
503Service Unavailable[RFC7231, Section 6.6.4]
504Gateway Timeout[RFC7231, Section 6.6.5]
505HTTP Version Not Supported[RFC7231, Section 6.6.6]
506Variant Also Negotiates[RFC2295]
507Insufficient Storage[RFC4918]
508Loop Detected[RFC5842]
509Unassigned
510Not Extended[RFC2774]
511Network Authentication Required[RFC6585]
512-599Unassigned

参考资料:

        IANA:Hypertext Transfer Protocol (HTTP) Status Code Registry

        IETF:Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

        HTTP response status codes

        HTTP Status Codes

        

相关推荐

精选
获取系统SDK版本、判断手机ROM
Code

获取系统SDK版本、判断手机ROM

Build获取系统SDK版本Android中部分API的使用,需要在特定的SDK版本之后才能使用,因此在兼容老版本SDK的时候,经常需要判断API的版本。各种Android版本的对应关系参考《Android各版本对应的SDK版本》判断手机ROM有时候需要判断手机系统的ROM,检测ROM是MIUI、EMUI还是Flyme,可以使用getprop命令,去系统build.prop文件(关于build.p

3.7k
精选
AndroidStudio中各种中文乱码问题
Code

AndroidStudio中各种中文乱码问题

AndroidStudio中各种中文乱码问题1、编译Java错误信息乱码在出现这个Annotation processors must be explicitly declared now...问题的时候,正好也发现AndroidStudio Build Output错误信息都乱码。经常遇到各种问题,习惯了,现在遇到的问题,都是以后的答案。 1.1、修改项目build.gradle(无效)在整个p

2.4k
AndroidStudio 报错:has no declaration in the base values folder
Code

AndroidStudio 报错:has no declaration in the base values folder

在资源文件中正常定义的值,也能编译运行。昨天还正常,今天一打开就报错。应该又是AndroidStudio自身的Bug了。原因众说纷纭,参考Stack Overflow 一篇类似的讨论。解决:File => Invalidate Caches / Restart => Invalidate and Restart.

4.4k