1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
//解决方法: //引入命名空间: using System.Security.Cryptography.X509Certificates; using System.Net.Security; //定义方法: private static bool RemoteCertificateValidate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) { //为了通过证书验证,总是返回true return true; } //调用方法一: //在构造函数中调用: static WxRequest() { // 获取验证证书的回调函数 ServicePointManager.ServerCertificateValidationCallback+=RemoteCertificateValidate; } //方法二: //在WebRequest请求之前调用: ServicePointManager.ServerCertificateValidationCallback+=RemoteCertificateValidate; |
光子:亲测可用。我原来的代码写的是:ServicePointManager.ServerCertificateValidationCallback=RemoteCertificateValidate;
唯独少了个+号,…………………………%……&%%¥#¥¥¥%¥%………………
光子:2018/04/27/13:56 又出现了,有点效果。