1
我正在使用Powershell v4。在Powershell中未顯示API響應
我打電話給一個POST API並希望看到響應,當我運行Invoke-RestMethod
但它只是顯示一個新行。
我怎麼能輸出從API到控制檯的響應?我曾嘗試在Write-Host
和Write-Output
的腳本中運行它,但控制檯屏幕上沒有顯示任何內容。
PowerShell腳本:
$Response = Invoke-RestMethod -Uri https://localhost:8081/myAPI -Body '{"username":"xyz","password":"xyz"}' -ContentType application/json -Method POST
Write-Host $Response
我能看到的響應,當我curl
的API,但不能看到它在我的PowerShell腳本,我需要使用。
捲曲
curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' https://localhost:8081/myAPI
它看起來像它甚至沒有擊中API如無物從Powershell的觸發時出現在API日誌。不知道如何解決,如果這是問題。
你應該換你的語句在一個try catch塊,看看PowerShell是實際上得到。示例:https://stackoverflow.com/questions/18771424/how-to-get-powershell-invoke-restmethod-to-return-body-of-http-500-code-response –