3

我正在使用 Microsoft 的WinHttpRequestCOM 对象请求带有无效证书的网页:

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

除了调用Send引发异常:

0x80072F0D - The certificate authority is invalid or incorrect

我怎么知道WinHttpRequest我不在乎,我希望它检索我要求的页面?

4

1 回答 1

7

解决方案是忽略四种 SSL 错误

//Code is released into the public domain. No attribution required. 
IWinHttpRequest http = new WinHttpRequest();
http.Open("GET", url, false);

//ignore any TLS errors 
option = http.Option[WinHttpRequestOption_SslErrorIgnoreFlags];
options = options | SslErrorFlag_Ignore_All;
http.Option[WinHttpRequestOption_SslErrorIgnoreFlags] = option; 

    //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);
于 2012-08-22T20:35:23.860 回答