Dynamically add a client certificate to a HttpClient
Problem statement
What is the best way to dynamically add a client certificate to a HttpClient
in C#? I have an application that needs to call the same endpoint with different client certificates (We are calling an API on behalf of our clients).
Scenario:
We are not able to use named HttpClient
s because our customer base will grow and shrink dynamically. What I had in mind was to create a HttpClientFa开发者_JAVA百科ctory
so you could do the following. Doing so creates new problems e.g. socket exhaustion.
var factory = new HttpClientFactory()
var certificate = new X509Certificate2();
HttpClient customerClient = factory.CreateClient(certificate)
Research:
- https://github.com/dotnet/extensions/issues/932
精彩评论