有人知道在使用HttpClientFactory
时如何使用客户端证书吗?在我发现的所有示例中,您都需要在HttpMessageHandler
构造函数中提供一个HttpClient
,而在使用HttpClientFactory
services.AddHttpClient("NamedClient", client =>
{
var handler = new HttpClientHandler();
X509Certificate2 certificate = GetMyX509Certificate();
handler.ClientCertificates.Add(certificate);
client. // ?? How do I set the handler?
});
答案 0 :(得分:1)
您使用以下命令在http消息处理程序管道中添加HttpMessageHandler
:
services.AddHttpMessageHandler<HttpClientHandler>()
然后您使用以下命令注册处理程序:
services.AddTransient(provider =>
{
var handler = new HttpClientHandler();
X509Certificate2 certificate = GetMyX509Certificate();
handler.ClientCertificates.Add(certificate);
return handler;
});
答案 1 :(得分:1)
在火星@agua的帮助下,我能够使用它
courseSubjects