C# Core 3.1 - Getting error message "The SSL connection could not be established" when calling HttpClient SendAsync()

Viewed 5821

Env: Console App, C# Core 3.1, VS 2019

I'm executing the following line:

var response = await client.SendAsync(request).ConfigureAwait(false);

I'm getting the following error:

{"The SSL connection could not be established, see inner exception."}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233087
    HelpLink: null
    InnerException: {"Authentication failed, see inner exception."}
    Message: "The SSL connection could not be established, see inner exception."
    Source: "System.Net.Http"
    StackTrace: "   at System.Net.Http.ConnectHelper.<EstablishSslConnectionAsyncCore>d__4.MoveNext()\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at ...

Did some googling and found this:

https://github.com/dotnet/runtime/issues/28189

So I added

AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);

right before the above line. Still getting the error.

I have a bunch of code prior to the executed line:

httpClientHandler = new HttpClientHandler
{
    SslProtocols = SslProtocols.Tls12
};

Plus code to add the certificate, header, content-type, etc. Not sure what is actually causing the error. Any ideas?

Thanks,

0 Answers
Related