REST API调用在Postman中工作正常,但通过Powershell提出了错误的请求

时间:2019-06-14 16:11:31

标签: rest powershell postman

我一直试图在Powershell脚本中实现api调用,并在Postman中对其进行了测试,并且运行良好,现在我正尝试在powershell中进行此操作,但是它收到了"error":"bad request"。该调用需要以下参数:

$Body = @{
'refresh_token' = 'xxx';
'acces_token' = 'xxx';
'expires' = 10000
} 
$Headers = @{
ContentType = "application/x-www-form-urlencoded"
Authorization = "Basic xxx=="
}
$Uri = "www.site.com"

我使用Invoke-RestMethod通过powershell发送请求,如下所示:

Invoke-RestMethod -Method POST -Uri $Uri -Headers $Headers -Body $Body

但是,当它应该发送令牌json或错误消息"error":"bad-request"时,它会发回"error":"token not expired"。 当我通过邮递员尝试时,它工作正常,我不知道错误在哪里。

我应该如何格式化请求才能使其正常工作?

0 个答案:

没有答案