gpt4 book ai didi

powershell - cUrl与Invoke-WebRequest

转载 作者:行者123 更新时间:2023-12-02 23:22:12 28 4
gpt4 key购买 nike

有人可以向我解释为什么cUrl(真正的网址)有效但Invoke-WebRequest无效吗?同一台机器,相同变量。在我看来,他们俩都应该做同样的事情,将文件上传到jfrog Artifactory。

$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无法正常工作。
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失败
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

最佳答案

原来PowerShell默认使用错误的TLS版本,需要明确告知使用1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
把它放在Invoke-WebRequest前面,一切都很好。

关于powershell - cUrl与Invoke-WebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47364244/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com