【问题标题】:API response is not showing in PowershellAPI 响应未在 Powershell 中显示
【发布时间】: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 日志中没有出现任何内容。如果这是问题,不知道如何解决。

【问题讨论】:

标签: rest powershell https http-post


【解决方案1】:

您的命令有语法错误。您的内容类型格式不正确。

你有:

-ContentType application/json

改成:

-ContentType "application/json"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-29
    • 2017-02-18
    • 2022-09-25
    • 2023-01-10
    • 1970-01-01
    • 2019-10-11
    • 1970-01-01
    相关资源
    最近更新 更多