HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

The request was aborted: Could not create SSL/TLS secure channel

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
couldrequesttlsthecreatesecurechannelsslnotaborted

Problem

We are unable to connect to an HTTPS server using WebRequest because of this error message:

The request was aborted: Could not create SSL/TLS secure channel.

We know that the server doesn't have a valid HTTPS certificate with the path used, but to bypass this issue, we use the following code that we've taken from another StackOverflow post:

private void Somewhere() {
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
}

private static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) {
   return true;
}


The problem is that server never validates the certificate and fails with the above error. Does anyone have any idea of what I should do?

Solution

In newer environments that support or enforce newer versions of SSL (TLS), you must add this before the code that makes an HTTP request:

// using System.Net;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons

Code Snippets

// using System.Net;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Use SecurityProtocolType.Ssl3 if needed for compatibility reasons

Context

Stack Overflow Q#2859790, score: 920

Revisions (0)

No revisions yet.