【发布时间】:2018-03-27 06:07:27
【问题描述】:
我在桌面 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,到目前为止我可以理解和测试这些步骤。
我怎么了?
【问题讨论】:
-
也许仍然相关。我已经在最低限度和所有参数下测试了 Invoke-WebRequest。错误已经出现在第一个参数(Uri)之后。
标签: .net powershell azure https invoke-command