HandyTools Hub

HTTP 状态码参考

浏览 HTTP 状态码(1xx–5xx)及其描述。

您的数据永远不会离开浏览器

100

Continue

The server has received the request headers and the client should proceed to send the request body.

101

Switching Protocols

The server is switching protocols as requested by the client, for example upgrading from HTTP to WebSocket.

102

Processing

The server has received and is processing the request, but no response is available yet (WebDAV).

103

Early Hints

Used to return some response headers before the final HTTP message, allowing the client to preload resources.

200

OK

The request has succeeded. The meaning depends on the HTTP method (GET, POST, PUT, DELETE, etc.).

201

Created

The request has been fulfilled and resulted in a new resource being created, typically after a POST request.

202

Accepted

The request has been accepted for processing but the processing has not been completed yet.

203

Non-Authoritative Information

The returned metadata may be from a third-party copy rather than the origin server.

204

No Content

The server successfully processed the request and is not returning any content body.

205

Reset Content

The server successfully processed the request and asks the client to reset the document view.

206

Partial Content

The server is delivering only part of the resource due to a range header sent by the client.

300

Multiple Choices

The request has more than one possible response. The user or user agent should choose one of them.

301

Moved Permanently

The URL of the requested resource has been changed permanently. The new URL is given in the response.

302

Found

The requested resource resides temporarily under a different URI. The client should continue to use the original URI.

303

See Other

The server sent this response to direct the client to get the requested resource at another URI with a GET request.

304

Not Modified

Indicates that the resource has not been modified since the version specified by the request headers (used for caching).

307

Temporary Redirect

The server sends this response to direct the client to a different URI, but the client must use the same HTTP method.

308

Permanent Redirect

The resource is now permanently located at another URI, and the client must use the same HTTP method for future requests.

400

Bad Request

The server cannot or will not process the request due to something that is perceived to be a client error (malformed syntax).

401

Unauthorized

The client must authenticate itself to get the requested response. Often called "unauthenticated" rather than "unauthorized".

403

Forbidden

The client does not have access rights to the content; the server is refusing to give the requested resource.

404

Not Found

The server can not find the requested resource. This is the most well-known HTTP error status code.

405

Method Not Allowed

The request method is known by the server but is not supported by the target resource.

408

Request Timeout

The server timed out waiting for the request from the client. The client may repeat the request without modifications.

409

Conflict

The request could not be completed due to a conflict with the current state of the target resource.

410

Gone

The requested content has been permanently deleted from the server, with no forwarding address.

413

Payload Too Large

The request entity is larger than limits defined by the server; the server might close the connection or return a Retry-After header.

414

URI Too Long

The URI requested by the client is longer than the server is willing to interpret.

415

Unsupported Media Type

The media format of the requested data is not supported by the server, so the server is rejecting the request.

418

I'm a teapot

The server refuses the attempt to brew coffee with a teapot. This is an April Fools joke from RFC 2324 (HTCPCP).

422

Unprocessable Entity

The request was well-formed but was unable to be followed due to semantic errors (WebDAV).

429

Too Many Requests

The user has sent too many requests in a given amount of time ("rate limiting"). The response should include a Retry-After header.

451

Unavailable For Legal Reasons

The server is denying access to the resource as a consequence of a legal demand (e.g., censorship or copyright).

500

Internal Server Error

The server has encountered a situation it does not know how to handle. This is a generic server error response.

501

Not Implemented

The request method is not supported by the server and cannot be handled. The server either does not recognize the request method or lacks the ability to fulfill it.

502

Bad Gateway

The server, while acting as a gateway or proxy, received an invalid response from the upstream server.

503

Service Unavailable

The server is not ready to handle the request. Common causes are server maintenance or temporary overloading.

504

Gateway Timeout

The server, while acting as a gateway or proxy, did not get a response in time from the upstream server.

HTTP 状态码速查是一份可搜索、按颜色分类的响应码目录,收录的都是你在日志和 API 里真正常遇到的码。不用再翻规范原文,几秒钟就能查到 307 或 429 是什么意思。它服务于调试失效接口的开发者、读代理日志的运维工程师,以及需要按正确状态码分支来写错误处理的任何人。

这份参考到底收录了什么

这份列表是刻意挑选的,而非穷举。它收录 38 个码,了解这个范围,能让你在期望的某个码缺席时不至于困惑。

类别数量收录的码
1xx4100、101、102、103
2xx7200、201、202、203、204、205、206
3xx7300、301、302、303、304、307、308
4xx15400、401、403、404、405、408、409、410、413、414、415、418、422、429、451
5xx5500、501、502、503、504

明显的空缺包括 305 Use Proxy 和 306、402 Payment Required、其余一些 4xx 码(如 406、407、411、412、416、417、426、428 和 431),以及所有高于 504 的 5xx 码。这份参考描述的是常见行为,而不是完整的 IANA 注册表。

搜索与筛选

搜索框接受三类查询。完整的三位数字精确匹配,所以 404 只返回 Not Found。较短的数字串按前缀匹配,所以 40 会列出所有以 40 开头的七个码,5 会列出全部五个服务器错误。其余内容会同时对状态码名称和描述做不区分大小写的匹配,所以 teapot 能找到 418,rate 能找到 429。

分类标签与搜索是配合关系,而不是替代搜索。选中 4xx 会把列表限定在客户端错误,再在搜索框里输入会进一步收窄这个子集。选中一个分类会清掉未搜索的码,方便你单独浏览某一类。

容易混淆的那些码

401 对 403。401 Unauthorized 表示请求缺少有效的认证凭据;403 Forbidden 表示凭据已被识别,但不授予访问权限。客户端明明只是没登录却返回 403,泄露的信息更少,却会误导调用方。

301 对 302。301 是永久移动,告诉爬虫和浏览器更新记录;302 是临时移动,会为后续请求保留原网址。它们的同类 307 和 308 分别表示保留原 HTTP 方法的临时和永久重定向,不像 301 和 302 历史上允许改变方法。

502 对 503 对 504。三者的来源都是中间层或过载的源站。502 是上游返回了畸形的响应,503 是有意拒绝,504 是超时。Retry-After 头在 503 和 429 上最有意义。

204 对 200。204 No Content 用空响应体确认成功,这在 DELETE 之后很常见。返回带空响应体的 200 合法,但不够精确。

这些状态码从哪来

核心状态码由 HTTP 语义规范及相关文档定义。少数条目有特定出处:102 Processing 和 422 Unprocessable Entity 是 WebDAV 扩展,103 Early Hints 支持预加载,451 Unavailable For Legal Reasons 是为被法律屏蔽的内容新增的,而 418 可追溯到一份愚人节 RFC。参考在描述里注明了这些来源,让你能区分标准工作、扩展和玩笑。由于这个集合是挑选过的,某个出现在 IANA 注册表却不在这里的码,未必就是无效的;它只是不在本页维护的日常清单里。

结合上下文理解一个响应

看到状态码时,下一个有用的问题是:修复该由谁负责。4xx 属于调用方:改请求、加凭据、放慢速度或修正请求体。5xx 属于服务器或其运维:稍后重试、检查上游服务或翻日志。仅这一刀就能告诉你重试循环是否说得通。

方法和语义同样重要。一次成功的 DELETE 往往更适合用 204 No Content 表达,而不是带空响应体的 200;201 Created 应带上指向新资源的 Location 头。405 Method Not Allowed 应在 Allow 头里列出可接受的方法,429 则应携带 Retry-After。这些头部提示不在本参考的范围内,却是正确使用每个码的一部分。

状态码也只是契约的一半,响应头和缓存状态同样承载含义。304 Not Modified 是缓存命中,不是错误;而被浏览器自动跟随的 3xx,等客户端代码观察到时可能已经看起来像 200。

常见错误

在响应体里塞错误信息却返回 200,这会破坏所有检查状态码的客户端。把永久移动写成 302,导致积累的搜索信号丢失。把 401 当作「不允许」来用,在应该用 403 的地方返回它,或反过来。对 4xx 盲目重试:400、401 或 422 在请求改变之前不会成功。以及遇到任何意外都用 500,而更具体的 502、503 或 504 本可以指向真正的病因。

相关工具

常见问题

这份参考一共收录了多少个状态码?

共 38 个:1xx 类 4 个,2xx 类 7 个,3xx 类 7 个,4xx 类 15 个,5xx 类 5 个。分类标签会显示这些数量,并随筛选结果更新。

为什么列表里没有 306 或 425?

这份列表是经过挑选的常见状态码集合,而不是完整的 IANA 注册表。306 在实践中未使用,而像 425 Too Early 这类已注册但罕见的码被省略了。搜索或分类筛选只会在实际收录的 38 个码上生效。

搜索 40 会返回什么?

纯数字查询按前缀匹配,所以 40 会返回所有以这两个数字开头的码:400、401、403、404、405、408 和 409。而像 404 这样的完整三位查询是精确匹配,只返回那一个码。

418 是真实的 HTTP 状态码吗?

它最初是 RFC 2324(超文本咖啡壶控制协议)里的愚人节玩笑,之所以被收录,是因为它已经成了一个广为人知的文化梗。它不属于 HTTP 核心规范,也不应用于真实的错误处理。

502、503、504 在实际中有什么区别?

502 Bad Gateway 表示代理或网关从上游服务器收到了无效响应;503 Service Unavailable 表示服务器暂时拒绝请求,通常因为维护或过载;504 Gateway Timeout 表示上游服务器没有及时响应。

这份参考会解释 WebDAV 状态码吗?

会。像 102 Processing 和 422 Unprocessable Entity 这类码的描述里会标注 WebDAV,让你知道某个码来自扩展规范而非核心规范。

由 HandyTools Hub 团队审校 · 最后更新