双向验证证书地址请求方式

【双向验证证书地址请求方式】url:请求地址
value:请求参数
cerPath:P12证书路径
password:证书密码
public static HttpResult PostRequest( string url, object value, string certPath, string password)
{
try
{
var parameters = JsonWrapper.SerializeObject(value);
byte[] data = https://www.it610.com/article/Encoding.UTF8.GetBytes(parameters);
var request = (HttpWebRequest)WebRequest.Create(url);
request.ContentLength = data.Length;
request.Headers.Add(“cache-control”, “no-cache”);
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(CheckValidationResult);
X509Certificate cert = new X509Certificate(certPath, password, X509KeyStorageFlags.MachineKeySet);
request.ClientCertificates.Add(cert);
request.Method = “POST”;
request.ContentType = “application/json”;
var stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
return new HttpResult
{
StatusCode = response.StatusCode,
Data = https://www.it610.com/article/JsonWrapper.DeserializeObject(content)
};
}
catch (System.Exception e)
{
throw e;
}
}

    推荐阅读