Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Posting on Qlik Community is temporarily paused. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
sheikhsaqib
Partner - Contributor
Partner - 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 (2)
1 Solution

Accepted Solutions
sheikhsaqib
Partner - Contributor
Partner - 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

2 Replies
sheikhsaqib
Partner - Contributor
Partner - 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);
}
}
}

DBIT
Contributor III
Contributor III

Hi just curious, what was the actual issue? I have a similar problem I'm struggling to solve and this may give me a clue.

 

Thanks.