开发者

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 HttpClients 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜