ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,518 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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;
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.