首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cUrl与Invoke-WebRequest

cUrl与Invoke-WebRequest
EN

Stack Overflow用户
提问于 2017-11-18 08:55:25
回答 1查看 4.9K关注 0票数 2

有人能向我解释为什么cUrl (真正的cUrl)起作用,而Invoke-WebRequest却不行吗?同样的机器,同样的变量。在我看来,他们都应该做同样的事情,上传一个文件到。

代码语言:javascript
复制
$headers = @{
  'X-JFrog-Art-Api' = $apiKey
  "Content-Type" = "application/json"
  "Accept" = "application/json"
}

Invoke-WebRequest -InFile $file -Method Put -Uri "$ARTIFACTORY_HOST/third-party/test/readme.md" -Headers $headers -Verbose

这个PowerShell不工作。

代码语言:javascript
复制
curl -T readme.md "${ARTIFACTORY_HOST}/third-party/test/readme.md " \
-H "X-JFrog-Art-Api: ${apiKey}" \
-H "Content-Type: application/json" \
-H "Accept: application/json"

cUrl工作。

PowerShell失败了

代码语言:javascript
复制
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest -InFile $file -Method Put -Uri "https:// ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-19 23:21:51

原来PowerShell默认为错误的TLS版本,需要专门告诉它使用1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

把它放在Invoke-WebRequest前面,一切都很好。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47364244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档