Home > Net >  Asp.net post access HTTPS interface submitted. P12 certificate hint according to the validation proc
Asp.net post access HTTPS interface submitted. P12 certificate hint according to the validation proc

Time:09-26

//Https post request
HttpWebRequest the req=(HttpWebRequest) WebRequest. Create (" https://www.xxx.com/api ");
The req. Method="POST";
The req. ContentType="application/x - WWW - form - urlencoded";

//Https authentication
X509Certificate2 cer=new X509Certificate2 (HttpContext. Current. Server MapPath (" cert/123. P12 "), "123", X509KeyStorageFlags. PersistKeySet | X509KeyStorageFlags. MachineKeySet);
The req. ClientCertificates. Add (cer);

CodePudding user response:

Before the first call:
ServicePointManager. ServerCertificateValidationCallback +=RemoteCertificateValidate;

Private static bool RemoteCertificateValidate (object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error)
{
//in order to pass the certificate verification, always return true
return true;
}

CodePudding user response:

# 1 positive solution, direct returns true
  • Related