有时候调用https接口时会提示如下错误:
基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。
1,先加入命名空间:
1 | using System.Net.Security; |
2,再重载CheckValidationResult方法,返回true
1 | public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) |
3,然后在 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
前面加上如下一行代码:
1 | ServicePointManager.ServerCertificateValidationCallback = |