2012-10-14 194 views
4

我有下面的代码,这导致了WebException,我无法弄清楚为什么我的生活。 Windows 8 RTM上的VS2012/.Net 4.5 RTM。ServerCertificateValidationCallback被忽略

ServicePointManager.CertificatePolicy = null; 
    ServicePointManager.CheckCertificateRevocationList = false; 
    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; 

    var request = WebRequest.Create(url) as HttpWebRequest; 
    request.ServerCertificateValidationCallback = delegate { return true; }; 

    var response = request.GetResponse(); 

    WebException was unhandled 
    The request was aborted: Could not create SSL/TLS secure channel. 

我最初有回调作为自己的方法,它从来没有被调用过。任何想法为什么我无法忽略SSL验证错误并将所有敏感数据发送到未知Web服务器?

+0

当您尝试使用其他SSL服务器(如https:// www.google.com)时会发生什么?我认为你的连接在启动SSL/TLS握手之前失败了。 – Dai

+0

你说得对,我使用了另一台服务器(使用有效的SSL,但通过IP检索,原始服务器自签名),并执行回调并检索内容。任何想法可能导致连接在回调之前中断,当它在Firefox和IE10中都可用时? – Joe

+0

我不能告诉你 - 你必须使用像Wireshark这样的数据包嗅探器来查看你的程序与Firefox/IE相比的表现。但是有几件事情浮现在脑海中:您是否使用了错误的端口号,或者没有足够快地启动TLS握手? – Dai

回答