当前位置:首页 > Windows程序 > 正文

来对远程X.509证书的验证

2024-03-31 Windows程序

今天写措施的时候挪用到一个第三方的DLL文件,本机调试一切都正常,但是措施不是随处事器以后一直提示一个BUG:"根本连接已经封锁: 未能为SSL/TLS 安适通道成立信任关系"。
后来把DLL文件进行反编译,,发明是在获得请求的时候堕落了。

引用  WebResponse response = WebRequest.Create("https://……").GetResponse();

界说一个类,来对长途X.509证书的验证,进行措置惩罚惩罚,返回为true.我们要本身界说一个类,然后在客户单挪用WCF处事之前,执行一次即可。代码如下:

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; } }

在WebRequest.Create("https://……").GetResponse();挪用操纵点前先挪用这个要领: Util.SetCertificatePolicy();

标签:

原文地点:https://www.cnblogs.com/xingyadian/p/8970516.html

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/33436.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494585访问次数
  • 建站天数
  • 友情链接