Power Shell を使用して、リクエストから成功またはエラーのステータス コードを取得する必要があります。そして、私は常に空白のステータスを取得しています。
Invoke-WebRequest と Invoke-RestMethod を試してみました。通話には成功しましたが、ステータス コードを取得する方法が見つかりません。
ここでは、現在書かれている方法は次のとおりです。
$resource = "some url"
$Logfile = "C:/path/log.log"
function LogWrite
{
Param([string]$logstring)
Add-content $logfile -value $logstring
}
Try
{
$Response = Invoke-WebRequest -Method Post -Uri $resource
Write-Output("Success.")
LogWrite $Date
LogWrite SuccessOnCall
LogWrite $Response.StatusCode
}
Catch
{
$ErrorMessage = $_.Exception.Message
Write-Output($ErrorMessage)
$FailedItem = $_.Exception
Write-Output($FailedItem)
LogWrite $Date
LogWrite ErrorOnCall
LogWrite $ErrorMessage
Break
}
私も試しました:
LogWrite "StatusCode:" $Response.Exception.Response.StatusCode.value__
この質問 (およびその他のリンク) を使用しました: Invoke-Restmethod: how do I get the return code?
これを解決しようとして、私のログには「SuccessOnCall」と書かれていますが、StatusCode は空白です。
ありがとうございました。