首页 > 其他 > 详细

关于解决 请求被中止:无法建立SSL / TLS安全通道

时间:2014-11-25 23:15:46      阅读:397      评论:0      收藏:0      [点我收藏+]

我使用HttpWebRequest访问其他网站时,出现"请求被中止:无法建立 SSL / TLS安全通道"错误,于是goog和百度了一番,提供的答案基本 是:ServicePointManager.ServerCertificateValidationCallback写委托

public ResponseModel GetHtml(string url)
{
 
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
 
}
 
private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}

 但这种方法对我无效,该出现的错误还是继续出现.

最终解决办法是,在访问url前执行语句  ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;即可

public ResponseModel GetHtml(string url)
{
     ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
}

关于解决 请求被中止:无法建立SSL / TLS安全通道

原文:http://www.cnblogs.com/Byrd/p/4121979.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!