赞
踩
WebResponse response = WebRequest.Create("https://……").GetResponse();
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
- internal class AcceptAllCertificatePolicy : ICertificatePolicy
- {
- public AcceptAllCertificatePolicy()
- {
- }
-
-
- public bool CheckValidationResult(ServicePoint sPoint,
- X509Certificate cert, WebRequest wRequest, int certProb)
- {
- // Always accept
- return true;
- }
- }
ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;
- private bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
- {
- return true;
- }
- HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);前面加上如下一行代码:
- ServicePointManager.ServerCertificatidationCallback = ValidateServerCertfiate;//验证服务器证书回调自动验证
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。