PowerShell Invoke-RestMethod无法创建TLS / SSL安全通道

问题描述

我正在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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...