开发者

Dynamically add a client certificate to a HttpClient

开发者 https://www.devze.com 2022-12-07 18:53 出处:网络
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

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

精彩评论

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