Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
sheikhsaqib
Contributor
Contributor

Issue will connection to QLik sense REST API on public DNS via c#

Its showing 

AuthenticationException: The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch, RemoteCertificateChainErrors

I tried multiple approaches but it's not working. 

Labels (1)
1 Solution

Accepted Solutions
sheikhsaqib
Contributor
Contributor
Author

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);
}
}
}

View solution in original post

1 Reply
sheikhsaqib
Contributor
Contributor
Author

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);
}
}
}