如何使用IWinHttpRequest忽略无效证书?

时间:2012-08-22 20:22:58

标签: winapi winhttp

我正在使用Microsoft的WinHttpRequest COM对象来请求包含无效证书的网页:

IWinHttpRequest http = new WinHttpRequest();
http.Open("GET", url, false);
http.Send(null);

除了对Send的调用引发异常外:

0x80072F0D - The certificate authority is invalid or incorrect

我如何告诉WinHttpRequest我不在乎,我希望它能够检索我要求的页面?

1 个答案:

答案 0 :(得分:7)

解决方案是忽略four kinds of SSL errors

IWinHttpRequest http = new WinHttpRequest();
http.Open("GET", url, false);

//ignore all SSL errors 
http.Option[WinHttpRequestOption_SslErrorIgnoreFlags] = SslErrorFlag_Ignore_All; 

    //SslErrorFlag_Ignore_All                                  0x3300
    //Unknown certification authority (CA) or untrusted root   0x0100
    //Wrong usage                                              0x0200
    //Invalid common name (CN)                                 0x1000
    //Invalid date or certificate expired                      0x2000

http.Send(null);
  

注意:任何代码都会发布到公共域中。无需归属。