zoukankan      html  css  js  c++  java
  • 解决“未能创建 SSL/TLS 安全通道”异常

    引用:

    https://www.cnblogs.com/ahdung/p/10489229.html

    之前写了一个桌面程序,程序会间歇性访问某个https接口,一直用的好好的,今天突然报错了,异常就发生在访问接口的地方,曰“请求被中止,未能创建 SSL/TLS 安全通道。”,另外有台电脑也有跑该程序,也是同样的报错,看来是接口方改动过什么了。

    搜索一番,原因应该是,接口方变更了安全协议,而客户端并未启用该协议。解决办法自然就是:让客户端启用该协议。具体就是在发起网络请求之前确保ServicePointManager.SecurityProtocol中含有服务端所用的安全协议,如果不知道或希望客户端健壮一点,当然最简单的方式就是把所有可用的协议都启用,随你服务端将来怎么换。代码如下:

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

    但如果客户端是基于.net framework 4.0,SecurityProtocolType枚举中并没有Tls11和Tls12,这就需要直接填值:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                           | SecurityProtocolType.Tls
                                           | (SecurityProtocolType)0x300 //Tls11
                                           | (SecurityProtocolType)0xC00; //Tls12
  • 相关阅读:
    python-并发编程之多进程
    python-继承以及继承问题和多态
    python-面向对象的命名空间和组合
    python-初识面向对象
    python-模块与包
    python-异常处理
    ios开发相关网站
    优秀Android开源项目
    知名应用背后的第三方开源项目
    贪心算法
  • 原文地址:https://www.cnblogs.com/johnsonshu/p/12356861.html
Copyright © 2011-2022 走看看