【问题标题】:Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a sendInvoke-WebRequest:底层连接已关闭:发送时发生意外错误
【发布时间】:2023-01-25 02:07:20
【问题描述】:

执行Invoke-WebRequest时遇到如下错误信息。在网上查到需要在命令前加上如下命令,但还是报错。

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

目前已知要连接的服务器启用TLS1.2(仅),服务使用https,连接防火墙,连接telnet servicename 443,执行PowerShell的服务器启用TLS1.0 、1.1、1.2 和 PowerShell 使用 v4。 0。 作为对比,我用自己的电脑,执行Invoke-WebRequest成功,但是PowerShell是v5.1。请问是不是PowerShell版本问题? 请帮助,谢谢。

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:15
+ $WebConnect = Invoke-WebRequest -URI $strHTTPS -Credential $credential
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest)     [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId :     WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

【问题讨论】:

  • 谢谢你。通过这种方式,我确认我的 PowerShell 不支持 TLS1.2 传输。我也让对方开启了VM的TLS1.0和1.1,但是还是一样的错误信息。我还发现您提供的网址中的错误信息(关于TLS1.2)并没有出现。我猜其他问题导致了这个错误?

标签: powershell invoke-webrequest


【解决方案1】:

在我的例子中,添加了一个回调到Unexpected error occurred running a simple unauthorized Rest query 并且 Invoke-RestMethod 有效,即使 Invoke-WebRequest 无效。

【讨论】:

    猜你喜欢
    • 2020-12-30
    • 2020-05-15
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多