How to obtain numeric HTTP status codes in PowerShell

后端 未结 4 671
天命终不由人
天命终不由人 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 18:23

    It looks very easy

    $wc = New-Object NET.WebClient
    $wc.DownloadString($url)
    $wc.ResponseHeaders.Item("status")
    

    You can find the other available Response Headers in the ResponseHeaders property (like content-type, content-length, x-powered-by and such), and retrieve any of them via the Item() method.

    ... but as rob mentions below, sadly, the status property is not available here

提交回复
热议问题