c# - 异常 : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host

标签 c# .net ssl https vsto

我正在尝试使用 HTTPClient 调用 API,但出现标题中提到的异常。

经过 stackoverflow 的一些研究后,我发现在服务调用之前添加这一行可以解决问题

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

但此人没有解释这一行的原因,也没有说明这一行是否会影响程序的任何其他部分。

注意:我连接的服务器使用 https。

提前致谢。

最佳答案

来自MSDN在文章中您会发现必须在对 HTTPS 端点进行任何调用之前设置此属性。

This property selects the version of the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocol to use for new connections that use the Secure Hypertext Transfer Protocol (HTTPS) scheme only; existing connections are not changed. Note that no default value is listed for this property, on purpose. The security landscape changes constantly, and default protocols and protection levels are changed over time in order to avoid known weaknesses. Defaults will vary depending on individual machine configuration, and on which software is installed, and on which patches have been applied.

关于c# - 异常 : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46092544/

相关文章:

c# - 如何将 IEnumerable<object> 转换为 List<IFoo>,其中每个对象都是一个 IFoo?

android - 如何信任我的应用程序中的所有自签名证书

php - curl 错误 (58) : unable to set private key file: '/var/www/work/xml/keys/client.pem' type PEM

c# - 我希望将日期时间显示为正确的日期,但在 Gembox 选项中我找不到将格式设置为日期的选项

c# - RestSharp是否有缓存

c# - 如何制作支持泛型类型的 HTML Helpers?

.net - REST API 仅设置对象的某些属性

c# - DataGridView 列宽百分比

c# - 如何在 .net 中取消转义和重新转义字符串?

c++ - 如何使用相应的 X509 证书验证私有(private) RSA 签名