zoukankan      html  css  js  c++  java
  • 关于解决 请求被中止:无法建立SSL / TLS安全通道(The request was aborted: Could not create SSL/TLS secure channel)的问题

    我使用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); 
    } 
    

     整个世界安静多了.哈哈

  • 相关阅读:
    人月神话阅读笔记之二
    人月神话阅读笔记之三
    人月神话阅读笔记之一
    清楚浮动的10种方法
    WEB颜色值得设定
    文件上传 FileReader()
    Git学习笔记(三)
    Git学习使用笔记(二)
    Git使用学习笔记 (一)
    小知识点(JS)
  • 原文地址:https://www.cnblogs.com/Kingly/p/2965594.html
Copyright © 2011-2022 走看看