Using custom SSL client certificates System.Net.HttpClient on Mono(在 Mono 上使用自定义 SSL 客户端证书 System.Net.HttpClient)
问题描述
我正在使用来自 NuGet 的 Microsoft HTTP 客户端库,我基本上是在尝试允许 TLS使用 X509Certificate2 证书在 HttpClient 中进行身份验证.
I'm using Microsoft HTTP Client Libraries from NuGet and I'm basically trying to allow TLS authentication in HttpClient using X509Certificate2 certificates.
我尝试过这样创建客户端:
I have tried creating the client like this:
但是 certHandler.ClientCertificates
失败了,因为这个 getter 是 没有在 Mono 中实现,所以我得到了 NotImplementedException.(我不确定为什么这仍然是 TODO.)
However certHandler.ClientCertificates
is failing because this getter is not implemented in Mono, so I get a NotImplementedException from that. (I'm not sure why that's still a TODO.)
到目前为止,我运气不佳.任何想法如何在 Mono 环境中简单地在 HttpClient 上设置客户端证书?
So far I'm out of luck. Any ideas how can I simply set a client certificate on HttpClient in Mono environment?
推荐答案
貌似只是简单的可以把客户端证书集合传给CreateWebRequest中的HttpWebRequest,所以既然继承不行,我就干脆从单声道复制/粘贴类并添加实现.
It looks as if it's simply a matter of being able to pass the client certificate collection to the HttpWebRequest in CreateWebRequest, so since inheriting won't work, I just copy/pasted the class from mono and added the implementation.
现在在您的代码中使用 WebRequestHandlerWithClientCertificates 而不是 WebRequestHandler
now in your code use a WebRequestHandlerWithClientCertificates instead of a WebRequestHandler
这篇关于在 Mono 上使用自定义 SSL 客户端证书 System.Net.HttpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!