Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure'

cyy 21 Reputation points
2022-03-09T00:13:45.8+00:00

I have a .NET Console 6 to access API data. The application works on my desktop (Windows 10) but an error "System.Net.Http.HttpRequestException: The SSL connection could not be established" is thrown when running the application on Windows Server 2012 R2. The code is below.

private static async Task<string> GetBobjDataAsync(string path)
{
var handler = new HttpClientHandler
{
UseDefaultCredentials = true
};
var bobj = new HttpClient(handler);

        HttpResponseMessage response = await bobj.GetAsync(new Uri(path));
        if (response.IsSuccessStatusCode)
        {
            return response.Content.ReadAsStringAsync().Result;
        }
        else
        {
            return response.StatusCode.ToString();
        }
    }

My Windows Server 2012 R2 is using TLS 1.2. How can I resolve this TLS issue?

Thanks in advance!!

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
322 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,240 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Pamani, Praveen Kumar 0 Reputation points
    2023-01-27T21:04:42.3533333+00:00

    I have a same issue , After some windows 10 Enterprise 20H2 updates all my httpClient request are failing with

    Authentication failed because the remote party sent a TLS alert: '112'.

    Here is the sample i am trying on .net 6 Azure Function, Any help is appreciated.

     var httpClientHandler = new HttpClientHandler                
    {
                        SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls13 | System.Security.Authentication.SslProtocols.Tls11,
                        UseDefaultCredentials = true
                    };
    
                    using var client = new HttpClient(httpClientHandler);                
                    client.Timeout = TimeSpan.FromSeconds(3000);
                    var msg = new HttpRequestMessage(HttpMethod.Get, uri);   
                    var res = await client.SendAsync(msg);
    

  2. cyy 21 Reputation points
    2023-03-31T15:20:17.12+00:00

    Thank you all!

    The issue got resolved after the (SAP) site updated their software.

    0 comments No comments