Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Its showing
AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors
I tried multiple approaches but it's not working.
I fixed it by using the below code
using (HttpClientHandler handler = new HttpClientHandler())
{
handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, certChain, policyErrors) => true;
handler.ClientCertificates.Add(certificate);
handler.ClientCertificates.Add(certificate2);
using (HttpClient client = new HttpClient(handler))
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, endpoint);
request.Content = new ByteArrayContent(postBytes);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
request.Headers.Add("x-qlik-xrfkey", xrfkey);
HttpResponseMessage response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
string data = await response.Content.ReadAsStringAsync();
ticketID = data.Substring(data.IndexOf("Ticket") + 9, 16);
}
else
{
// Handle unsuccessful response
throw new Exception("HTTP request failed with status code: " + response.StatusCode);
}
}
}
I fixed it by using the below code
using (HttpClientHandler handler = new HttpClientHandler())
{
handler.ServerCertificateCustomValidationCallback = (httpRequestMessage, cert, certChain, policyErrors) => true;
handler.ClientCertificates.Add(certificate);
handler.ClientCertificates.Add(certificate2);
using (HttpClient client = new HttpClient(handler))
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, endpoint);
request.Content = new ByteArrayContent(postBytes);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
request.Headers.Add("x-qlik-xrfkey", xrfkey);
HttpResponseMessage response = await client.SendAsync(request);
if (response.IsSuccessStatusCode)
{
string data = await response.Content.ReadAsStringAsync();
ticketID = data.Substring(data.IndexOf("Ticket") + 9, 16);
}
else
{
// Handle unsuccessful response
throw new Exception("HTTP request failed with status code: " + response.StatusCode);
}
}
}