How to deal with ServerCertificateCustomValidationCallback?,

Dondon510 221 Reputation points
2022-09-12T09:10:11.617+00:00

Hi,

How to deal with ServerCertificateCustomValidationCallback?,

I occasionally facing the codes goes to the ServerCertificateCustomValidationCallback, I expect to retry it..

                    HttpClientHandler clientHandler = new HttpClientHandler();  
                    //clientHandler.SslProtocols = System.Security.Authentication.SslProtocols.Tls13;  
                    clientHandler.ServerCertificateCustomValidationCallback += (sender, cert, chain, sslPolicyErrors) =>  
                    {  
                        return true;  
                    };  
  
                    var client = new HttpClient(clientHandler);  
                    var url = new Uri($"https://xxx.xxx.com/?per_page=500&page={pageNo}");  
  
                    client.DefaultRequestHeaders.Accept.Clear();  
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Token", token);  
  
                    var response = await client.GetAsync(url);  
                    HttpStatusCode statusCode = response.StatusCode;  
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
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2022-09-12T16:28:48.103+00:00

    not sure your question. the default certificate validation checks the certificate chain to determine if valid. your code says, trust any certificate, that is do no validation.

    0 comments No comments