首页 > 其他分享 >https请求报ssl连接失败解决方法

https请求报ssl连接失败解决方法

时间:2022-11-22 11:55:28浏览次数:45  
标签:请求 certificate Util ssl static https SetCertificatePolicy trust any

Util.SetCertificatePolicy();在请求时加上这句调用
HttpWebRequest request = WebRequest.Create(loginurl) as HttpWebRequest;

 

public static class Util
{
/// <summary>
/// Sets the cert policy.
/// </summary>
public static void SetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;
}

/// <summary>
/// Remotes the certificate validate.
/// </summary>
private static bool RemoteCertificateValidate(
object sender, X509Certificate cert,
X509Chain chain, SslPolicyErrors error)
{
// trust any certificate!!!
System.Console.WriteLine("Warning, trust any certificate");
return true;
}
}

标签:请求,certificate,Util,ssl,static,https,SetCertificatePolicy,trust,any
From: https://www.cnblogs.com/banfeng/p/16914690.html

相关文章