C
C#2y ago
ryder96_

How to use certificate on HttpClient

I'm trying to add a certificate to my http client but on request it gives the exception RemoteCertificateNameMismatch and i do not understand why it fails i followed the instructions on msdn doc. Code where i create my client
c#
builder.Services.AddHttpClient("sslClient")
.ConfigurePrimaryHttpMessageHandler(() =>
{

var handler = new HttpClientHandler();
var certificate = new X509Certificate2("Certificates/certificate.pfx", "password");
handler.ClientCertificates.Add(certificate);
return handler;
});
c#
builder.Services.AddHttpClient("sslClient")
.ConfigurePrimaryHttpMessageHandler(() =>
{

var handler = new HttpClientHandler();
var certificate = new X509Certificate2("Certificates/certificate.pfx", "password");
handler.ClientCertificates.Add(certificate);
return handler;
});
Code where i create it and I do the get request
c#
var httpClient = _httpClientFactory.CreateClient("sslClient");
try
{
var response = await httpClient.GetAsync(endpoint);
} catch ...
c#
var httpClient = _httpClientFactory.CreateClient("sslClient");
try
{
var response = await httpClient.GetAsync(endpoint);
} catch ...
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server