I'm using ASP.NET Core 2.2, in which I'm consuming secure API (e.g.https://google.com) from non-secure portal. But I am getting below error while requesting API :
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
I have already tried with ServerCertificateCustomValidationCallback
, ServerCertificateCustomValidationCallback
, ServicePointManager.SecurityProtocol
etc. but it didn't work.
When i am using ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
, then I'm getting error:
System.NotSupportedException: The requested security protocol is not supported"
Sample code(s) which i have already tried ::
1.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls |
SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12 |
SecurityProtocolType.Ssl3;
2.
using (var httpClientHandler = new HttpClientHandler())
{
httpClientHandler.ServerCertificateCustomValidationCallback =
(message, cert, chain, errors) => { return true; };
using (var client = new HttpClient(httpClientHandler))
{ // somecode }
}
3.
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback =
(httpRequestMessage, cert, cetChain, policyErrors) =>
{
return true;
},
SslProtocols = SslProtocols.Tls12 |
SslProtocols.Tls11 |
SslProtocols.Tls |
SslProtocols.Ssl3 |
SslProtocols.Ssl2 |
SslProtocols.Default |
SslProtocols.None
};