日期:2014-05-16 浏览次数:20565 次
ServicePointManager.ServerCertificateValidationCallback = RemoteCertificateValidate;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
Uri uri = new Uri(@url);
HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
InstallCertificate(clientP12_Path, clientP12PassWord, StoreLocation.CurrentUser, StoreName.My);
X509Certificate cer = new X509Certificate(clientP12_Path, clientP12PassWord);
request.ClientCertificates.Add(cer);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "post";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Proxy = null;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
responseText = reader.ReadToEnd();
}
return responseText;
// 导入证书
private static bool InstallCertificate(string certFilePath, string password, StoreLocation location, StoreName storeName)
{
try
{
if (!File.Exists(certFilePath))
{
return false;
}
byte[] certData = File.ReadAllBytes(certFilePath);