2013/02/21
httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる!
一般的な Web Programmer ならば、HTTP Status code はすべて暗記していると聞きました。
しかし、僕は初心者なので、なかなか覚えきれていないので、HTTPのステータスコードをさがすのに便利な PowerShell 関数を用意しました。Get-HttpStatusCode 関数です。インストール方法は以下のコードをprofile.ps1にコピーするなどです。
function Get-HttpStatusCode { param( [string]$Code ) begin { $enumType = [System.Net.HttpStatusCode] $codeNames = [enum]::GetNames($enumType) $codes = $codeNames | %{ [pscustomobject]@{ Code = [string][long][enum]::Parse($enumType, $_) Description = $_ -creplace "([a-z])([A-Z])",'$1 $2' } } } process { if(![string]::IsNullOrEmpty($code)) { $codes|?{$_.Code.IndexOf($Code) -eq 0 -or $_.Description.IndexOf($Code) -eq 0} } else { $codes } } }
使い方は以下のとおりです。
4xx なコードを列挙する。
PS> Get-HttpStatusCode 4 Code Description ---- ----------- 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 Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Request Entity Too Large 414 Request Uri Too Long 415 Unsupported Media Type 416 Requested Range Not Satisfiable 417 Expectation Failed 426 Upgrade Required
40x なコードを列挙する
PS> Get-HttpStatusCode 40 Code Description ---- ----------- 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 Timeout 409 Conflict
500 ってなんだっけ?
PS> Get-HttpStatusCode 500 Code Description ---- ----------- 500 Internal Server Error
403 ってなんだっけ?
PS> Get-HttpStatusCode 403 Code Description ---- ----------- 403 Forbidden
Bad なんとかってなんだっけ?
PS> Get-HttpStatusCode Bad Code Description ---- ----------- 400 Bad Request 502 Bad Gateway
とりあえず全部みるか。
PS> Get-HttpStatusCode
元ネタ:httpstatus コマンドで、HTTP のステータスコードをすばやくしらべる! - tokuhirom's blog.
ネタなんで蹴らないで…
プライバシーポリシー