How to ignore invalid certificates with IWinHttpRequest?

[亡魂溺海] 提交于 2019-12-11 02:24:34

问题


i am using Microsoft's WinHttpRequest COM object to request a web-page with an invalid certificate:

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

Except that the call to Send throws an exception:

0x80072F0D - The certificate authority is invalid or incorrect

How do i tell WinHttpRequest that i don't care, and i want it to retrieve the page i asked for?


回答1:


The solution is to ignore 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);

Note: Any code is released into the public domain. No attribution required.



来源:https://stackoverflow.com/questions/12080824/how-to-ignore-invalid-certificates-with-iwinhttprequest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!