HTTPステータスコード

登録済みのHTTPステータスコードすべてについて、意味、出てくる場面、定義されている場所をまとめています。

100ContinueThe server received the request headers and the client should send the body.
101Switching ProtocolsThe server is switching to the protocol the client asked for in the Upgrade header.
102ProcessingThe server accepted the request and is still working on it.
103Early HintsHeaders sent ahead of the final response so the client can start preloading resources.
104Upload Resumption SupportedThe server supports resuming this upload if it is interrupted.
200OKThe request succeeded.
201CreatedThe request succeeded and created a new resource.
202AcceptedThe request was accepted for processing, which hasn't finished.
203Non-Authoritative InformationSuccess, but a proxy changed the response the origin server sent.
204No ContentThe request succeeded and there is no body.
205Reset ContentSuccess; the client should reset the form or view that sent the request.
206Partial ContentThe response holds only the byte range the client asked for.
207Multi-StatusThe body holds separate status codes for several operations.
208Already ReportedMembers of this collection were already listed earlier in the same 207 response.
226IM UsedThe response is a delta applied to the current instance, not the full resource.
300Multiple ChoicesThe resource has several representations and the client should choose one.
301Moved PermanentlyThe resource has a new permanent URL, given in the Location header.
302FoundThe resource is temporarily at the URL in the Location header.
303See OtherThe result is at another URL, which the client should fetch with GET.
304Not ModifiedThe cached copy is still valid, so no body is sent.
305Use ProxyThe resource must be accessed through the proxy in the Location header.
306(Unused)Reserved; it was once used for Switch Proxy and is no longer used.
307Temporary RedirectThe resource is temporarily at another URL; repeat the request there with the same method and body.
308Permanent RedirectThe resource has moved permanently; repeat the request at the new URL with the same method and body.
400Bad RequestThe server can't process the request because it is malformed.
401UnauthorizedThe request has no valid credentials for this resource.
402Payment RequiredReserved for future use.
403ForbiddenThe server understood the request but refuses to allow it.
404Not FoundThe server has nothing at this URL.
405Method Not AllowedThe resource exists but doesn't support this HTTP method.
406Not AcceptableThe server can't produce a response in any format the Accept headers allow.
407Proxy Authentication RequiredThe client must authenticate with the proxy first.
408Request TimeoutThe server gave up waiting for the client to finish sending the request.
409ConflictThe request conflicts with the current state of the resource.
410GoneThe resource existed but has been removed permanently.
411Length RequiredThe server needs a Content-Length header.
412Precondition FailedA condition in the request headers, such as If-Match, is false.
413Content Too LargeThe request body is larger than the server accepts.
414URI Too LongThe URL is longer than the server accepts.
415Unsupported Media TypeThe server doesn't accept the body's format.
416Range Not SatisfiableThe requested byte range is outside the resource.
417Expectation FailedThe server can't meet the Expect header.
418I'm a teapotA joke code from RFC 2324, kept reserved as "(Unused)" because so much software already recognizes it.
421Misdirected RequestThe request reached a server that can't answer for this host.
422Unprocessable ContentThe request is well formed but its content fails validation.
423LockedThe resource is locked.
424Failed DependencyThe request failed because a request it depended on failed.
425Too EarlyThe server won't process a request that might be replayed.
426Upgrade RequiredThe client must switch to another protocol, named in the Upgrade header.
428Precondition RequiredThe server requires a conditional request, such as one with If-Match.
429Too Many RequestsThe client has sent too many requests in a given time and is being rate limited.
431Request Header Fields Too LargeThe headers, or one header, are too large.
451Unavailable For Legal ReasonsThe resource can't be served for legal reasons.
500Internal Server ErrorThe server hit an unexpected condition.
501Not ImplementedThe server doesn't support the functionality needed, such as the request method.
502Bad GatewayA gateway or proxy got an invalid response from the server behind it.
503Service UnavailableThe server can't handle the request right now.
504Gateway TimeoutA gateway or proxy didn't get a response from the server behind it in time.
505HTTP Version Not SupportedThe server doesn't support the HTTP version of the request.
506Variant Also NegotiatesContent negotiation is misconfigured on the server.
507Insufficient StorageThe server can't store what it needs to complete the request.
508Loop DetectedThe server found an infinite loop while processing the request.
510Not ExtendedThe request needs an HTTP extension the server requires.
511Network Authentication RequiredThe client must authenticate to get network access.
419Page ExpiredLaravelThe CSRF token is missing or expired.
420Enhance Your CalmTwitter (historical)The client is being rate limited.
444No Responsenginxnginx closed the connection without sending a response.
494Request Header Too Largenginxnginx's code for headers over its buffer limits.
495SSL Certificate ErrornginxThe client certificate failed verification.
496SSL Certificate RequirednginxA required client certificate wasn't sent.
497HTTP Request Sent to HTTPS PortnginxA plain HTTP request reached a port that expects TLS.
499Client Closed RequestnginxThe client closed the connection before nginx sent the response.
509Bandwidth Limit ExceededApache / cPanelThe site has used up its bandwidth allowance.
520Web Server Returned an Unknown ErrorCloudflareThe origin server returned something Cloudflare couldn't use.
521Web Server Is DownCloudflareThe origin server refused Cloudflare's connection.
522Connection Timed OutCloudflareCloudflare couldn't establish a TCP connection to the origin in time.
523Origin Is UnreachableCloudflareCloudflare can't reach the origin server.
524A Timeout OccurredCloudflareCloudflare connected to the origin, but it didn't respond in time.
525SSL Handshake FailedCloudflareThe TLS handshake between Cloudflare and the origin failed.
526Invalid SSL CertificateCloudflareCloudflare couldn't validate the origin's certificate.
530Origin DNS ErrorCloudflareCloudflare returns 530 together with a 1xxx error, most often 1016 (origin DNS error).

Select a code

Pick a code from the list to see when it is used, the specification that defines it and a command to try it. Use the arrow keys to move through the list.
64 registered codes · 17 unofficial

HTTPステータスコードとは?

HTTPレスポンスはすべて、リクエストがどうなったかを示す3桁のステータスコードで始まります。最初の桁がクラスを表し、1xxは情報、2xxは成功、3xxはリダイレクト、4xxはリクエストの誤り、5xxはサーバーのエラーを意味します。

ステータスコードは、2022年にRFC 7231を置き換えたRFC 9110(HTTP Semantics)と、429 Too Many Requests を定義するRFC 6585などいくつかのRFCで定義されています。公式のレジストリはIANAが管理しています。RFC 9110では2つのコードの名前が変わりました。413は Content Too Large(旧 Payload Too Large)、422は Unprocessable Content(旧 Unprocessable Entity)です。番号と動作は変わっていません。

実際に目にするコードの中には、レジストリにないものもあります。nginxはレスポンスの準備ができる前にクライアントが接続を切ると499を記録し、Cloudflareはオリジンサーバーから使えるレスポンスを得られないと520〜526を返し、Laravelはフォームのトークン(CSRF)が期限切れになると419を返します。これらは非公式として別にまとめています。

ステータスコードは、APIテストで最初に確認すべきものです。レスポンスの残りはすべてこれに左右されるからです。201 Created ならPOSTで新しいリソースが作られたこと、404ならリソースが存在しないこと、500ならサーバーが失敗したことを示します。500の場合、ボディは期待していたJSONではなくエラーページかもしれません。

使い方

  1. 11xxから5xxまでグループ分けされた一覧(非公式のコードは最後)を見るか、クラスのボタンで絞り込みます。
  2. 2番号、名前、症状で検索します。たとえば 404、5xx、redirect、timeout、あるいは Unprocessable Entity のような旧名称です。ページ内のどこからでも / を押すと検索欄に移動します。
  3. 3コードを選ぶか、矢印キーで一覧を移動すると、その意味、出てくる場面、定義している仕様、比較すべき関連コードが表示されます。
  4. 4Try it の下にある curl コマンドをコピーすると、testingapis.comのステータスエンドポイントからそのコードを返させることができます。リンクもコピーでき、/ja/tools/http-status/#429 で429を直接開けます。

トラブルシューティング

トークンを送ったのに401になる
トークンが期限切れか、形式が不正か、間違ったヘッダーで送られているか、Bearer の接頭辞が抜けています。どれが原因かは、レスポンスヘッダーの WWW-Authenticate に書かれていることがよくあります。403であれば、トークンは有効でも権限がないという意味です。
JSONのボディで415になる
リクエストに Content-Type: application/json ヘッダーがないため、サーバーがボディをJSONとして扱っていません。curlの -d は、ヘッダーを指定しない限り application/x-www-form-urlencoded を送ります。
リダイレクトの後、POSTがGETに変わる
クライアントは301や302に従うとき、ボディなしのGETとしてリクエストを送り直します。メソッドを維持する必要があるサーバーは、307か308を返すべきです。
ロードバランサーから502や504が返る
アプリケーションの手前にあるプロキシが有効な応答を受け取れませんでした。アプリケーションがクラッシュしたか接続を閉じた場合は502、プロキシのタイムアウトより時間がかかった場合は504です。原因はアプリケーション自体のログでわかります。
nginxのログに499がある
レスポンスの準備ができる前にクライアントがあきらめました。ユーザーがページを離れたか、クライアントや上流のプロキシがタイムアウトしたためです。よくある原因は、バックエンドへのリクエストが遅いことです。

よくある質問

401と403の違いは何ですか?

401 Unauthorized は、サーバーがあなたが誰なのかを知らないという意味です。認証情報がない、期限切れ、または間違っています。403 Forbidden は、誰なのかはわかっているけれど、そのIDにはその操作が許可されていないという意味です。ログインし直せば401は解決できますが、403は解決できません。

不正な入力に対して、APIは400と422のどちらを返すべきですか?

どちらも使われています。よくある使い分けは、不正な形式のJSONのようにサーバーがまったく読めないリクエストには400、必須項目の欠落や無効なメールアドレスのように、形式は正しくてもルールに反するデータには422です。

502、503、504の違いは何ですか?

3つとも、たいていはアプリケーションの手前にあるプロキシやロードバランサーから返されます。502 Bad Gateway は後ろのサーバーから無効な応答を受け取ったこと、503 Service Unavailable はサービスが過負荷かメンテナンス中であること、504 Gateway Timeout は後ろのサーバーが時間内に応答しなかったことを意味します。

どのリダイレクトコードを使えばよいですか?

301と308は恒久的、302と307は一時的なリダイレクトです。307と308ではクライアントが同じメソッドとボディでリクエストを送り直す必要がありますが、301や302の後では、クライアントは通常POSTをGETに変えてしまいます。POSTの後で結果ページに移動させるには、303 See Other を使ってください。

418 I'm a teapot は本当にあるステータスコードですか?

1998年のエイプリルフールのジョークで、コーヒーポットの制御について書かれたRFC 2324が出どころです。すでに多くのソフトウェアが認識しているため、RFC 9110では418を「未使用だが予約済み」としています。本物のエラーに使うためのものではありません。

特定のステータスコードをアプリがどう扱うか、どうやってテストできますか?

指定したコードを返すエンドポイントを呼び出します。GET https://api.testingapis.com/api/status/503 は503を返し、Retry-After のようにそのステータスに通常付くヘッダーも返します。200から599までのどのコードでも使えます。