Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.
This repository was archived by the owner on Sep 1, 2025. It is now read-only.

use on server centOS has error #4

@chaosact

Description

@chaosact

I use it at local has been success. when i use on the server it's not work.

throw exception
Unhandled Exception: System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.) ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

I use flowing code make it right

       private readonly HttpClient _client;
       public WebClient(Environment environment)
        {
            HttpClientHandler httpClientHandler = new HttpClientHandler();
            httpClientHandler.ServerCertificateCustomValidationCallback += ValidateCert;
            _client = new HttpClient(httpClientHandler) { BaseAddress = new Uri($"{environment.BaseUrl}") };
            _client.DefaultRequestHeaders.Add("User-Agent", "stuart-client-csharp/1.3.1");
        }

        private bool ValidateCert(HttpRequestMessage message, X509Certificate2 x509Certificate2, X509Chain x509Chain, SslPolicyErrors errors)
        {
            if (x509Certificate2 != null && x509Chain != null)
            {
                if (x509Certificate2.Verify())
                {
                    return x509Chain.Build(x509Certificate2);
                }
            }
            return false;
        }

but I don't think that's right. may be contais onther good ideas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions