Rest Powershell中未显示API响应

Rest Powershell中未显示API响应,rest,powershell,https,http-post,Rest,Powershell,Https,Http Post,我正在使用Powershell v4 我正在调用POST API,希望在运行Invoke RestMethod时看到响应,但它只显示了一行新行 如何将响应从API输出到控制台?我曾尝试在脚本中使用Write Host和Write Output运行它,但控制台屏幕上没有显示任何内容 PowerShell脚本: $Response = Invoke-RestMethod -Uri https://localhost:8081/myAPI -Body '{"username":"xyz","pass

我正在使用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

从Powershell触发时,API日志中没有显示任何内容,因此看起来它甚至没有命中API。如果出现问题,不确定如何解决。

您的命令有语法错误。您的contenttype格式不正确

你有:

-ContentType application/json
将其更改为:

-ContentType "application/json"

您应该将语句包装在try-catch块中,看看Powershell实际得到了什么。例子: