【问题标题】:Unable to curl from Windows 10 Powershell with X-API-KEY无法使用 X-API-KEY 从 Windows 10 Powershell 卷曲
【发布时间】:2017-05-10 05:50:55
【问题描述】:

我一直在尝试从 windows powershell 卷曲,但没有运气。

curl -O -J -H  @{'X-Api-Key' = 'abcdefghijk'} https://my.repo.com/abc/xyz

我收到以下错误

curl : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ curl -O -J -H  @{'X-Api-Key' = 'abcdefgh'} ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

【问题讨论】:

  • 提及 curl 是 PowerShell cmdlet Invoke-WebRequest 的别名,而不是像许多其他人可能知道的那样 curl。

标签: windows powershell curl httprequest


【解决方案1】:

正如@Robin 在他的评论中指出的那样; curl 是 Invoke-WebRequest 的别名(有关更多信息,请参阅您的异常详细信息!

所以基本上......它不是卷曲!

这意味着您提供的开关可能不会按您的预期映射。

首先要提到的是,虽然 PowerShell 允许您使用缩短的参数名称,但您真的,真的不应该使用它们!

  • -O = -OutFile(可能不是你想要的……)
  • -J = ...没有!
  • -H = -Headers(看起来很适合你)

我认为这是您问题的根本原因 - 您需要查看 CmdLet 的文档

Get-Help Invoke-WebRequest
Get-Help Invoke-WebRequest -Online ## this will open in browser with full details

【讨论】:

  • 谢谢。我试过没有 -O 和 -J,只是用 '-H' 没有运气。是不是 Invoke-WebRequest 不接受/理解 x-api-key 之类的?
  • 同样的错误信息?您应该查看文档中的其他开关;例如-Method
猜你喜欢
  • 2018-01-04
  • 1970-01-01
  • 2018-06-07
  • 2021-10-05
  • 2016-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多