0

当我通过 powershell 向 rest api Postmarkapp 发送请求时,我遇到了这些错误

使用方法获取时

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" |
4

1 回答 1

0

您提供的脚本不完整 - 它以|. 执行请求之前需要有效的令牌,否则您将收到此错误:

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."}

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

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

然后像这样添加标题(带有$before Token):

Invoke-RestMethod $Uri -Method Get -Headers @{'X-Postmark-Server-Token' ="$Token" }  -ContentType "application/json" 
于 2019-05-08T22:41:18.400 回答