1

I am using a domain with an untrusted TLS (SSL) certificate so I could debug something.

This is my code:

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;

In case there was an error with the request I would like to print the HTTP status code.

The problem is that the line in the except clause is never executed and instead I get the following error:
enter image description here

Even if I run the executable without debugger attached it still causes errors.

How do I handle an OleObject exception in Inno Setup?

4

1 回答 1

1

如您所料,WinHttpReq.Send投掷

证书中的主机名无效或不匹配

该异常被您的except块捕获。永远不会执行该except子句是不正确的!

在该except块中,您尝试读取WinHttpReq.Status(HTTP 状态代码)。但是还没有 HTTP 状态代码,因为证书验证发生任何 HTTP 交换之前。所以第二个异常是由WinHttpReq.Statusgetter 抛出的:

WinHttp.WinHttpRequest:完成此操作所需的数据尚不可用。

而且您没有任何处理程序。因此异常被 Inno Setup 本身捕获并显示为“运行时错误”。

于 2016-03-21T15:59:00.647 回答