【问题标题】:Powershell Invoke-WebRequest Error - Interacting with Azure DatabricksPowershell Invoke-WebRequest 错误 - 与 Azure Databricks 交互
【发布时间】: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


【解决方案1】:

尝试强制使用 TLS 1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

【讨论】:

    【解决方案2】:

    感谢您的回答。我今天早上能够测试这个。这是可能的。 我的最终解决方案现在在脚本中如下所示。

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Invoke-WebRequest -Uri "https://IpAddress/resource" -Method Post -ContentType "application/xml"
    

    【讨论】:

      猜你喜欢
      • 2012-07-26
      • 1970-01-01
      • 1970-01-01
      • 2021-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多