HTTPステータスコード

1. HTTP Status Codeとは

webサイトとの通信には「http」というプロトコルが使われています。

このプロトコルでは、クライアントがリクエスト送信して、サーバーがそのレスポンスを返します。

しかし、サーバーのレスポンスが1つ1つ違ったら成功なのか失敗なのか分かりません。

そこで、サーバーのレスポンスの一行目に、

HTTP/{バージョン} {ステータスコード} {ステータス}

とするルールが決まっています。

2. よく知られているコード

・404 Not Found

ファイルが見つからない時のステータスコードです。

適当なURLを入力したり、古い記事のリンクにアクセスした時に出てくる事が多いです。

・301 Moved Permanently

別のURLへ移動する時に使われるステータスコードです。

「Location」というヘッダーに指定されたURLへリダイレクトされます。

直接、301という数字を見る事は少ないですが、実際はかなり遭遇しています。

・413 Request Entity Too Large

不正なリクエストを送信すると返されるステータスコードです。

ヘッダーが長すぎたりすると遭遇します。

3. 面白いコード

・418 I’m a tea pot

mozilla.orgでは、「サーバーは、ティーポットでコーヒーを淹れようとする試みを拒否します。」と書かれています。

そう、これはエイプリルフールに発行されたジョーク「HTCPCP」のステータスコードですw

RFC 2324 – Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) (ietf.org)

Hyper Text Coffee Pot Control Protocolですか。。

中々センスがありますね。。

ついでに、 天下のGoogle様も418のページを用意していますw

4. ステータスコード一覧

100 Continue
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
300 Ambiguous
301 Moved Permanently Moved
302 Found Found
303 See Other RedirectMethod
304 Not Modified
305 Use Proxy
306 - Unused
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Time-out
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Large
415 Unsupported Media Type
416 Requested range not satisfiable
417 Expectation Failed
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Time-out
505 HTTP Version not supported

4. 参考

HTTP レスポンスステータスコード – HTTP | MDN (mozilla.org)

HTTPで「418 I’m a tea pot」を実装してはいけない(2018/10/18追記) – Qiita

RFC 2324 – Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0) (ietf.org)

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です