can使用PowerShell访问API,但可以使用Postman,Python或Curl访问

发布于 2025-02-13 22:58:58 字数 785 浏览 4 评论 0原文

我试图使用命令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-webrequestInvoke-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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

权谋诡计 2025-02-20 22:58:58

自己弄清楚。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文