【问题标题】:Powershell and Rest API PostmarkPowershell 和 Rest API 邮戳
【发布时间】:2019-09-26 14:46:48
【问题描述】:

当我通过 powershell 向 rest api Postmarkapp 发送请求时,出现这些错误

当使用metod get时

Invoke-RestMethod : Cannot send a content-body with this verb-type.

当使用metod post时

Server Error in '/' Application. The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.
Requested URL: /deliverystats

脚本

$Uri         = 'https://api.postmarkapp.com/deliverystats'
Invoke-RestMethod $Uri -Method Post -Headers @{'X-Postmark-Server-Token' =" Token" }  -ContentType "application/json" |

【问题讨论】:

  • 您是否尝试过使用curl 指定here 来测试您的请求?

标签: powershell postmark


【解决方案1】:

您提供的脚本不完整 - 它以 | 结尾。 在执行请求之前需要一个有效的令牌,否则你会得到这个错误:

Invoke-RestMethod : {"ErrorCode":10,"Message":"No Account or Server API tokens were supplied in the HTTP headers. Please add a header for either 
X-Postmark-Server-Token or X-Postmark-Account-Token."}

您的代码有' Token',这是一个常量,可能不是X-Postmark-Server-TokenX-Postmark-Account-Token 标头的有效值。您没有显示$Token 是如何设置的,但它可能应该是这样的:

$Token = 'xxxxxxxxxxxxx' #your account specific token
$uri = 'https://api.postmarkapp.com/deliverystats'

然后像这样添加标题($Token 之前):

Invoke-RestMethod $Uri -Method Get -Headers @{'X-Postmark-Server-Token' ="$Token" }  -ContentType "application/json" 

【讨论】:

    猜你喜欢
    • 2017-05-26
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    相关资源
    最近更新 更多