Home > Misc > C# Error while calling API – Could not create SSL/TLS secure channel

C# Error while calling API – Could not create SSL/TLS secure channel

Other day, we were getting following error while calling SSL enables 3rd party API from C# console.

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

Fix:

  • Add below statement before making your API call, which validates the SSL certification.

ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};

  • Include following namespaces

using System.Security.Cryptography.X509Certificates;
using System.Net.Security;

🙂

 

Advertisement
Categories: Misc Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: