如何抑制 Indy IdHTTP 错误消息框?

How to suppress Indy IdHTTP error message box?

我有一个 IdHTTP 组件,当我收到 HTTP 错误(例如 404)时,Indy 会显示一个消息框。我想处理这个 "silent" 并防止 Indy 显示这个。

我没有找到任何参数来关闭它。有什么想法吗?

Indy 不显示消息框。它抛出异常。 VCL/FMX 框架内有默认的异常处理程序,如果您的代码中没有捕获到异常,它将向用户显示一个消息框。因此,只需在您的代码中捕获异常,例如:

try
{
    IdHTTP1->Get(...);
}
catch (const Exception &)
{
    // do something...
}

如果您需要对异常过滤进行更精细的控制,所有 Indy 特定的异常都派生自 EIdException,并且有很多后代(如 EIdHTTPProtocolException),例如:

try
{
    IdHTTP1->Get(...);
}
catch (const EIdHTTPProtocolException &)
{
    // an HTTP error occured, do something...
    // details about the HTTP error are in the exception object
}
catch (const EIdException &)
{
    // a non-HTTP Indy error occured, do something else...
}
catch (const Exception &)
{
    // some other error occured, do something else...
}