C # httpClient.SendAsync not sending client certificate

I have the following code snippet:

var url  ="https://localhost/Sensor/Sensors/Whitelist";
var cerX509 = new X509Certificate2(@"c:\Client.pfx", "PASSWORD");
var messageHandler = new WebRequestHandler();
messageHandler.ClientCertificateOptions = ClientCertificateOption.Manual;
messageHandler.ClientCertificates.Add(cerX509);
var message = new HttpRequestMessage(HttpMethod.Get, url);
var httpClient = new HttpClient(messageHandler);

I am trying to find out why my client certificate is not sent to the server when called httpClient.SendAsync(message), and I get 401.

When I replace the call httpClient.GetAsync(url), a certificate is sent.

I have control over the code on the server side, and when I use it httpClient.GetAsync, I can get the certificate using

X509Certificate2 certificate = request.GetClientCertificate();

when i use httpClient.SendAsync(message), the method call request.GetClientCertificate()returns null.

Why doesn't SendAsync send a certificate?

+4
source share

Source: https://habr.com/ru/post/1588943/


All Articles