苏飞论坛

标题: 万能框架完美解决:“请求被中止: 未能创建 SSL/TLS 安全通道”问题 [打印本页]

作者: 站长苏飞    时间: 2016-10-8 11:28
标题: 万能框架完美解决:“请求被中止: 未能创建 SSL/TLS 安全通道”问题
万能框架完美解决:“请求被中止: 未能创建 SSL/TLS 安全通道”问题
我们先来看几个类似的问题

关于Htttphelper访问https://wx.qq.com无响应的解决方式
http://www.sufeinet.com/thread-16482-1-1.html


请求被中止: 未能创建 SSL/TLS 安全通道。
http://www.sufeinet.com/thread-17704-1-1.html


大家通过文章可以看的出来这个问题其实通常只需要配置
[C#] 纯文本查看 复制代码
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

就行了,但是每个系统环境不同,.net版本不同,SecurityProtocolType的选择项目也是不同的,在此


我为大家提供一个属性专门解决这个问题。


使用方法

当你使用万能框架时,只需要简单的一行代码即可
[C#] 纯文本查看 复制代码
 //创建Httphelper对象
            HttpHelper http = new HttpHelper();
            //创建Httphelper参数对象
            HttpItem item = new HttpItem()
            {
                URL = "http://wx.qq.com",//URL     必需项   
                SecurityProtocol = SecurityProtocolType.Tls,//当出现“请求被中止: 未能创建 SSL/TLS 安全通道”时需要配置此属性
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            //获取请求的Cookie
            string cookie = result.Cookie;


提供几个常用的SecurityProtocolType选项


    SecurityProtocolType.Tls12


[C#] 纯文本查看 复制代码

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls


SecurityProtocolType是一个枚举值,大家只需要在写代码时选择一个即可。

好了就这样吧。

万能框架下载地址:http://httphelper.sufeinet.com/


作者: 客服~小小    时间: 2016-10-8 11:35
强烈支持楼主ing……
作者: songwenqi    时间: 2016-10-8 14:36
强烈支持楼主ing……
作者: sunny    时间: 2016-10-8 23:58
强烈支持楼主ing……
作者: sunny    时间: 2016-10-9 00:03
曾经使用代理IP抓取网站时也遇到过有些代理IP会出现这个问题“请求被中止: 未能创建 SSL/TLS 安全通道”,查询网上资料也是说加上SecurityProtocol = SecurityProtocolType.Tls这句,但当加上这句时,全部代理都失败了,后来只好放弃某部分出现此问题的代理IP,因时间问题后来也没现研究为什么有些代理IP会出现这个“请求被中止: 未能创建 SSL/TLS 安全通道”的问题了,如果大家有研究请讲解下,谢谢!
作者: 王二狗    时间: 2016-10-12 08:44
我遇到的这样的问题都是在页面跳转,跨域访问支付页面的时候,不过不是设置问题,是host的问题。
作者: lexlin    时间: 2016-11-18 15:27
报告,更新4.0版本后没有SecurityProtocol这个属性, host 属性也没有了,什么情况
作者: 站长苏飞    时间: 2016-11-18 15:56
lexlin 发表于 2016-11-18 15:27
报告,更新4.0版本后没有SecurityProtocol这个属性, host 属性也没有了,什么情况

这是框架,你用的是Htttphelper类,两回事
作者: lexlin    时间: 2016-11-22 16:40
好的,谢谢,已经解决了
作者: chenyuntao    时间: 2017-8-25 14:36
ServicePointManager.SecurityProtocol   这个是全局变量,如果是在多线程中对不同的网站访问设置这个变量值,互相之间会有冲突,请问有什么解决方案,尝试过加锁貌似也不行。
作者: 职业赌徒    时间: 2018-10-15 22:54
如图,万能框架这个问题可能还需要完善
(, 下载次数: 102)