关于解决 请求被停止:没法创建SSL / TLS安全通道

我使用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;便可url

public ResponseModel GetHtml( string url)
{
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
}
相关文章
相关标签/搜索