首先加上引用“System.Security.DLL”,其次在工程中
using System.Security.Cryptography.X509Certificates;
这样就可以使用“
X509Certificate Class
之后我们就可以
///构建请求的HttpWebRequest对象
HttpWebRequest hwrRequest = (HttpWebRequest)WebRequest.Create(
strValidatePageURL);
/// 从本地文件中加载证书
hwrRequest.ClientCertificates.Add(X509Certificate.CreateFromCertFile("c://motor.https.pem.cer"));
这是一个较简单的办法。
如果你遇到了“The underlying connection was closed. Could not establish a secure SSL/TLS connection"”的异常,那么请设置
hwrRequest.KeepAlive = true;
至于如何“在个人证书存储区获取证书”,参看下面的blog: