【发布时间】:2017-08-07 13:04:02
【问题描述】:
我正在使用 Powershell v4。
我正在调用 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 实际得到了什么。示例:stackoverflow.com/questions/18771424/…
标签: rest powershell https http-post