HTTP 状态码的职责是当客户端向服务器端发送请求时,描述返回的响应结果。借助状态码,用户可以知道服务器端是正常处理了请求,还是出现了什么类型的错误。
状态码类别
状态码以3位数字和原因短语组成,数字中的第一位描述状态码的类别,响应类别有以下5中:
类别 | 原因短语 | |
---|---|---|
1XX | 信息性状态码 | 接收的请求正在处理 |
2XX | 成功 | 请求正常处理完毕 |
3XX | 重定向 | 需要进行附加操作完成请求 |
4XX | 客户端错误 | 服务器无法处理请求 |
5XX | 服务端错误 | 服务器处理请求出错 |
常见状态码
状态码 | 原因短语 | 说明 |
---|---|---|
100 | Continue | 客户端在其初始请求中的请求头字段中发送Expect: 100-continue ,服务器如果支持此服务,将返回100状态码,表示服务器已经接收到请求头,并且客户端应继续发送请求主体 |
200 | OK | 请求成功 |
204 | No Content | 请求成功,但是没有响应主体返回 |
206 | Partial Content | 请求成功,只返回部分资源,用于范围请求的响应 |
301 | Move Permanently | 永久重定向,请求的资源已被永久的移动到新URI,返回信息会包括新的URI,浏览器会自动定向到新URI。今后任何新的请求都应使用新的URI代替 |
302 | Found | 临时重定向,与301类似。但资源只是临时被移动。客户端应继续使用原有URI |
303 | See Other | 临时重定向。与302类似,只是期望客户端通过GET方式重定向 |
307 | Temporary Redirect | 临时重定向。与302类似。只是期望客户端使用POST请求重定向 |
304 | Not Modified | 表示资源在由请求头中的If-Modified-Since 或If-None-Match 参数指定的这一版本之后,未曾被修改。不返回任何资源,客户端将使用缓存 |
400 | Bad Request | 请求报文语法错误,不能被服务器理解 |
401 | Unauthorized | 请求需要认证而未认证,或认证失败 |
403 | Forbidden | 资源被禁止访问 |
404 | Not Found | 资源不存在 |
412 | Precondition Failed | 先决条件不满足 |
416 | Requested Range not satisfiable | 范围请求无法满足 |
500 | Internal Server Error | 服务器故障或Web应用故障 |
503 | Service Unavailable | 由于超载或系统维护,服务器暂时的无法处理客户端的请求。延时的长度可包含在服务器的Retry-After 头信息中 |
504 | Gateway Time-out | 充当网关或代理的服务器,未及时从远端服务器获取请求 |