似乎已经提出并回答了这个问题,但到目前为止,我遇到的每个解决方案都无济于事。我正在编写一个 PowerShell 脚本来运行一些 REST API 来获取使用信息。我的脚本立即中断只是试图与服务器通信。为了测试,我正在做一个非常简单的命令:
Invoke-RestMethod 'https://server:4443/login'
它返回此错误:
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
我可以运行相同的命令,但使用 URL google.com 并且我得到了有效的返回,所以我知道该命令一般来说是有效的。
如果我在服务器本身上运行 curl 等效项,则事情会按预期完成。这是 curl 命令的详细输出的片段:
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.0 / DHE-RSA-AES256-SHA
* Server certificate:
* subject: CN=localhost
* start date: 2016-03-22 21:48:57 GMT
* expire date: 2026-03-20 21:48:57 GMT
* issuer: CN=localhost
* SSL certificate verify result: self signed certificate (18), continuing anyway.
我只是假设这是一个基于搜索相当通用的错误 PowerShell 返回的自签名证书问题。
我试过了:
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
和其他类似的方法(复杂的功能)来帮助忽略证书问题而没有运气。
我正在运行 PowerShell 5,以防万一。
我对 PowerShell 代码很满意,但这是我第一次尝试 Invoke-RestMethod,所以也许我遗漏了一些东西。任何见解都值得赞赏。