标签:
string cert = @"R:\apiclient_cert.p12"; string password = "10010000"; ServicePointManager.ServerCertificateValidationCallback=new RemoteCertificateValidationCallback(CheckValidationResult); X509Certificate cer = new X509Certificate(cert, password); HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); webrequest.ClientCertificates.Add(cer); webrequest.Method = "post"; HttpWebResponse webreponse = (HttpWebResponse)webrequest.GetResponse(); Stream stream = webreponse.GetResponseStream(); /*CheckValidationResult 的定义 */ private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { if (errors == SslPolicyErrors.None) return true; return false; }
注意:
C#有一点需要注意,除了在代码中使用apiclient_cert.p12之外还需要将该证书导入操作系统才能使用,
1、代码中使用;
2、导入操作系统,二者缺一不可。
.NET版本需要大于2.0
标签:
原文地址:http://www.cnblogs.com/danlis/p/5282768.html