can使用PowerShell访问API,但可以使用Postman,Python或Curl访问
我试图使用命令Indoke -webrequest -sbasicparsing $ request_string -method get -headers $ headers
,但我正在尝试使用powerShell从在线获得数据),但是我正在返回ind> ind> indoke-webrequest:webrequest:远程服务器返回了一个错误:(403)禁止。
我正在提供$ headers字典。奇怪的是,我可以使用Postman,Python和Curl访问API。只有在使用PowerShell命令时,我才会得到403错误。实际上,我使用Postman的代码片段来生成我的PowerShell代码,但它仍然无法使用! Postman的PowerShell代码片段是:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer {removed for security}")
$response = Invoke-RestMethod '{removed for security}' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
回顾一下,Indoke-webrequest
和Invoke-restmethod
不起作用。
这里的任何帮助将非常感谢。
谢谢!
I'm trying to get data back from an API online using Powershell with the command Invoke-WebRequest -UseBasicParsing $request_string -Method Get -Headers $headers)
but am getting back Invoke-WebRequest : The remote server returned an error: (403) Forbidden.
I am supplying a $headers dictionary. Strangely, I can access the API using Postman, Python, and cURL. It's only when using Powershell commands that I get the 403 error. In fact, I used Postman's Code Snippet feature to generate my Powershell code, and it still doensn't work! Postman's Powershell Code Snippet was:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer {removed for security}")
$response = Invoke-RestMethod '{removed for security}' -Method 'GET' -Headers $headers
$response | ConvertTo-Json
To recap, both Invoke-WebRequest
and Invoke-RestMethod
don't work.
Any help here is much appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自己弄清楚。
API供应商强制执行 https 要求,而不仅仅是 http 。显然,Postman,Python和Curl可以自己弄清楚并相应地更改请求,但Powershell不能。
Figured it out on my own.
The API vendor enforced https requirement instead of just http. Apparently, Postman, Python, and cURL can figure that out on their own and change the request accordingly, but Powershell cannot.