ASP核心HttpClientFactory模式使用客户端证书 [英] ASP Core HttpClientFactory Pattern Use Client Cert
本文介绍了ASP核心HttpClientFactory模式使用客户端证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道在使用HttpClientFactory
时如何使用客户端证书吗?在我发现的所有示例中,您都需要在HttpClient
构造函数中提供一个HttpMessageHandler
,而在使用HttpClientFactory
Any one know how to use client cert when using the HttpClientFactory
? In all the examples I've found you need to provide an HttpMessageHandler
in the HttpClient
constructor, which isn't available when using the HttpClientFactory
services.AddHttpClient("NamedClient", client =>
{
var handler = new HttpClientHandler();
X509Certificate2 certificate = GetMyX509Certificate();
handler.ClientCertificates.Add(certificate);
client. // ?? How do I set the handler?
});
推荐答案
在火星@agua的帮助下,我能够使用它
I was able to get it working with help from @agua from mars
services.AddHttpClient("myservice", client =>
{
client.BaseAddress = new Uri("https://localhost:8717");
}).ConfigurePrimaryHttpMessageHandler(h =>
{
var handler = new HttpClientHandler();
handler.ClientCertificates.Add(GetCert());
return handler;
});
这篇关于ASP核心HttpClientFactory模式使用客户端证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文