C#“请求被中止: 未能创建 SSL/TLS 安全通道”通用解决方案

有两种方式

第一种:执行代码前,加上

 ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

第二种,加上这一段也行,这两种方式,选一种即可,如果出错,项目请切换到net4.5以上

//http加载证书,ssl,如果出错,就切换到net4.5
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
 //http加载证书,ssl,如果出错,就切换到net4.5

就可以正常获取https链接的内容了,或者下载带有https链接的文件了

可以解决:

C# 未能创建 SSL/TLS 安全通道

C# 出现基础连接已经关闭:接收时发生错误

C#无法请求https链接的内容

猜你喜欢

转载自blog.csdn.net/Lccee/article/details/125799950