S
S
sivabur2015-12-27 13:32:58
C++ / C#
sivabur, 2015-12-27 13:32:58

How to fix: Request was aborted: Failed to create SSL/TLS secure channel?

Error Messages:
System.Net.WebException: The request was aborted: Failed to create SSL/TLS secure channel. in System.Net.HttpWebRequest.GetResponse()
The code where the error occurs:

string html = string.Empty;
            string url = "https://google.com";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.KeepAlive = true;
            
            //навсякий пожарный добавил в решений этой ошибки видел подобое
            request.Credentials = CredentialCache.DefaultCredentials;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            using (Stream stream = response.GetResponseStream())
            using (StreamReader reader = new StreamReader(stream))
            {
                html = reader.ReadToEnd();
            }

//Нашол решения что это строка должна помогать тут задаеться делегат возращающий true чтобы принимало любой сертификат
ServicePointManager.ServerCertificateValidationCallback += AcceptAllCertificatePolicy;

       //просто делегат возращающий всегда true
        public static bool AcceptAllCertificatePolicy(object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
serfer7, 2018-07-02
@serfer7

There was a similar problem, you need to insert a line before using the connection:
helped me.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question