2016-03-21 85 views
1

我正在使用具有不可信的TLS(SSL)证书的域,以便我可以调试某些内容。Inno设置异常未捕获

这是我的代码:

procedure test(); 
var 
    WinHttpReq: Variant; 
begin 
    WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1'); 
    try 
    WinHttpReq.Open('POST', 'https://tv.eurosport.com/', False); 
    WinHttpReq.SetRequestHeader('Content-Type', 'application/json'); 
    WinHttpReq.Send(''); 
    except 
    MsgBox(IntToStr(WinHttpReq.Status), mbError, MB_OK); 
    end; 
end; 

万一有一个与我想打印的HTTP状态代码请求的错误。

的问题是,except子句中的线永远不会执行,而是我得到以下错误:
enter image description here

即使我没有运行调试器附加可执行它仍然会导致错误。

如何处理Inno Setup中的OleObject异常?

回答

1

如你期望的那样,WinHttpReq.Send抛出

The host name in the certificate is invalid or does not match

这异常是由您的except块捕获。从不执行except子句!

except块中,您尝试读取WinHttpReq.Status(HTTP状态码)。但是目前还没有HTTP状态码,因为证书验证在之前发生了任何HTTP交换。因此,第二个异常由WinHttpReq.Status getter方法抛出:

WinHttp.WinHttpRequest: The data necessary to complete this operation is not yet available.

而且你不必为任何处理程序。因此,Inno Setup本身会捕获异常并显示为“运行时错误”。

+0

有什么办法可以在证书错误的except子句中的状态代码? – yuval