我在桌面PSVersion 5.1.14393.2155中使用PowerShell . 我正在尝试使用 Invoke-WebRequest . 使用的Azure VM不是防火墙等的一部分 . 所以我不应该在这里遇到任何问题或限制 .
我收到以下错误:
Invoke-WebRequest -Method Post -Uri 'https://IpAddress/resource'
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line: 1 char:1
+ Invoke-WebRequest -Method Post -Uri 'https://IpAddress/resource ...
+
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId: WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestComand
我已经使用Powershell脚本打了电话 . 另外,我在Powershell中根据请求调用了参数的命令参数 . 我能够测试一些Stackoverflow文章 . 没有成功 .
已经测试:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$result = Invoke-WebRequest -Uri "https://IpAddress/resource"
参考文章Powershell v3 Invoke-WebRequest HTTPS error,到目前为止,我可以理解并测试这些步骤 .
这跟我有什么不对?
2 回答
尝试强制TLS 1.2
谢谢您的回答 . 今天早上我能够测试一下 . 那是可能的 . 我的最终解决方案现在在脚本中看起来像这样 .