问题描述
我正在PowerShell脚本中调用Invoke-RestMethod,以将zip存档上传到Artifactory存储库。 我从本地计算机PowerShell ISE测试了脚本;上传完成,没有出现预期的问题。但是,当我在目标目标计算机上执行脚本时,看到返回错误:
请求已中止:无法创建SSL / TLS安全通道。
我已经阅读了许多与此错误相关的在线帖子;共识似乎是在脚本中的Invoke-RestMethod调用之前紧接添加以下行:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Ssl3
我添加了这一行,但问题仍然存在。
执行以下PowerShell:
[Net.ServicePointManager]::SecurityProtocol
返回:
Ssl3,Tls,Tls11,Tls12 提示已启用所有可用协议。
我的脚本片段现在看起来像这样:
$headers = @{"X-JFrog-Art-Api" = $artifactoryApiKey}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Ssl3
$return=Invoke-RestMethod -Uri $uri -InFile $sourceFile -Method Put -Headers $headers
如上所述,该脚本在我的本地计算机上执行没有问题。
服务器上安装的.Net 4.6.1返回错误。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)