How to add registry certificate to HttpWebRequest?

半腔热情 提交于 2019-12-03 21:35:51

This MS knowledge base article covers what you need - How to send a client certificate by using the HttpWebRequest and HttpWebResponse classes.

As described in the article, you have two options open to you:

  1. Use the X509Certificate class to read the cert from a .cer file.
  2. Use CryptoAPI calls to extract the certificate information directly from the certificate store.

The second option is a nuisance, and needs elevated trust to extract from the cert. store. So you'll want to go for option 1 if possible. Something like this:

X509Certificate Cert = X509Certificate.CreateFromCertFile("C:\\mycert.cer");
HttpWebRequest Request = (HttpWebRequest)WebRequest
                         .Create("https://YourServer/sample.asp");
Request.ClientCertificates.Add(Cert);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!