In my ASP.NET MVC project (.Net Framework 4.7.2), I am consuming as API which is hosted on another server developed by vendor. Whenever I tried to hit same API through code, I am getting an error – “The request was aborted: Could not create SSL/TLS secure channel.“. But when I hit same same API through SOAP UI from server (Windows 2019) where my code is deployed, it provide proper response without error.
Refer my below code to get more idea
try
{
var client = new RestClient(url);
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic " + XXXXXXX);
request.AddParameter("grant_type", "XXXXXXXX");
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
IRestResponse response = client.Execute(request);
return (response.Content);
}
catch (Exception ex)
{
throw ex;
}
Also refer API Report from Sslabs.com –