我看过如何使用
我可以通过浏览器或Postman发送证书并在服务器上看到它,但无法以编程方式实现。
有人能否确认或否认在将其作为请求的一部分发送之前,
快速反编译没有显示任何明显的问题,但请求管道中有许多因素。
示例代码:
WebRequestHandler
与HttpClient
嵌入证书到我的http请求的代码示例(请参见以下片段)。但是,我刚刚用自签名证书测试了一下,它并没有起作用。根据这篇文章,如果没有受信任的证书,这种方法将不起作用。我可以通过浏览器或Postman发送证书并在服务器上看到它,但无法以编程方式实现。
有人能否确认或否认在将其作为请求的一部分发送之前,
HttpClient
或WebRequestHandler
会执行任何类型的证书验证?快速反编译没有显示任何明显的问题,但请求管道中有许多因素。
示例代码:
var cert = new X509Certificate2(rawCert);
//This call fails, cannot check revocation authority.
//Specific error: The revocation function was unable to check
//revocation for the certificate.
//X509CertificateValidator.ChainTrust.Validate(cert);
var certHandler = new WebRequestHandler()
{
ClientCertificateOptions = ClientCertificateOption.Manual,
UseDefaultCredentials = false
};
certHandler.ClientCertificates.Add(cert);
var Certificateclient = new HttpClient(certHandler)
{
BaseAddress = new Uri("https://web.local")
};
var response = await Certificateclient.GetAsync("somepath");