running application from linux arm using httpclient I have exception calling an api http with self signed certificate

renzf 0 Reputation points
2023-02-04T15:55:17.5+00:00

Using dotnet 7 my application calls a https api service in my local network with self signed certificate.

I run it from a Windows client and I have no problems.

I run it from a linux arm raspberry device and I have the following exception:

"One or more errors occurred. (The SSL connection could not be established, see inner exception.)"

and the inner exception is "Received an unexpected EOF or 0 bytes from the transport stream."

This is the code:

        private void testConn(string apiUrl, LoginPostData loginData)
        {
            var handler = new HttpClientHandler();
            handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            //handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, cetChain, policyErrors) => { return true; };
            HttpClient client = new HttpClient(handler);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Task<HttpResponseMessage> response = client.PostAsJsonAsync(apiUrl, loginData);
            //...
        }
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,158 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,236 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
294 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,601 Reputation points
    2023-02-04T17:16:01.7733333+00:00

    Unlike windows, the Linux network layer does not support overriding ssl certificate validation. You must add the certificate as a trusted.

    how this is done will depend on your distro.


  2. Bruce (SqlWork.com) 55,601 Reputation points
    2023-02-04T17:16:38.5033333+00:00

    (Extra post to show previous)

    0 comments No comments