我正在尝试使用 System.Net.Http.HttpClient
(使用 GetStringAsync
)执行一个简单的获取请求。从我的 webapi asp.net 应用程序完成时请求失败,但它在浏览器和 postman 中正常工作。
请求失败,显示Authentication failed because the remote party has closed the transport stream.
Note: It works correctly when doing get request to other servers using TLS.
我使用以下内容来确认问题出在 ssl 上。使用这两行可以使请求有效,但显然禁用证书验证不是真正的解决方案。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
I tested the server using https://www.ssllabs.com and it seems that everything is working correctly on there. It supports TLS 1.1 and 1.2.
为了了解发生了什么,我查看了 wireshark 中的包,但由于我对 ssl 了解不多,所以我学的不多。查看来自浏览器请求的包,我可以看到它使用的是 TLS 1.2 协议(protocol)并且握手看起来是正确的。 下图显示了客户端发起两个单独的 ssl “ClientHello's”。由于某种原因,服务器没有响应 SSL 握手响应。
希望有人能帮我弄清楚这是怎么回事。
最佳答案
I tested the server using https://www.ssllabs.com and it seems that everything is working correctly on there. It supports TLS 1.1 and 1.2.
您的客户端仅进行 TLS 1.0 握手。如果服务器仅支持 TLS 1.1 和 TLS 1.2 但不支持 TLS 1.0,则连接将失败。由于现代浏览器都支持 TLS 1.2 浏览器。
关于c# - SSL 握手从 asp.net 应用程序失败 - 在浏览器中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34333746/