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 –