How to obtain numeric HTTP status codes in PowerShell

后端 未结 4 667
天命终不由人
天命终不由人 2021-01-30 17:35

I know of a few good ways to build web clients in PowerShell: the .NET classes System.Net.WebClient and System.Net.HttpWebRequest, or the COM object Msxml2.XMLHTTP. From what I

4条回答
  •  迷失自我
    2021-01-30 18:15

    Use the [system.net.httpstatuscode] enumerated type.

    ps> [enum]::getnames([system.net.httpstatuscode])
    Continue
    SwitchingProtocols
    OK
    Created
    Accepted
    NonAuthoritativeInformation
    NoContent
    ResetContent
    ...
    

    To get the numeric code, cast to [int]:

    ps> [int][system.net.httpstatuscode]::ok
    200
    

    Hope this helps,

    -Oisin

提交回复
热议问题