4

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,

MyDisplayName
  • 223
  • 5
  • 12
  • Added the following:```httpClientHandler.ServerCertificateCustomValidationCallback = (sender,certificate,chain,sslPolicyError)=>{return true;}; ```. This gives me a new error: ```System.Net.Http.HttpRequestException: An error occurred while sending the request. --->System.Net.Http.WinHttpException(80072F8F,12175):Error12175 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'A security error occurred'. at System.Threading.Tasks.RendezvousAwaitable`1.GetResult() at System.Net.Http.WinHttpHandler.StartRequestAsync(WinHttpRequestState state) --- End of inner exception stack trace ---``` – MyDisplayName Feb 24 '20 at 16:30
  • i got this same error in dotnet core 2.2 – Akash Limbani Mar 20 '20 at 05:32
  • I ended up using the RestSharp library. – MyDisplayName Apr 02 '20 at 21:16
  • 1
    Can you share your solution? I also tried to switch to RestSharp because of that error buit I keep getting it with RestSharp – baouss May 12 '20 at 03:55
  • Unfortunately I don't remember what I did to resolve this. – MyDisplayName May 13 '20 at 15:46
  • @MyDisplayName do you happen to recall now what you did to resolve this? – codewise Nov 10 '21 at 18:28

0 Answers0