Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIdHTTP error details
(08-16-2022, 07:30 PM)rlebeau Wrote:
(08-16-2022, 01:23 AM)Boba TC Wrote: when TIdHTTP::Get method throws out an EIdHTTPProtocolException, where do I find details of the error?

The EIdHTTPProtocolException::Message property contains the HTTP response code and response status text, as you noticed (these are the same values that you can get from the TIdHTTP::ResponseCode and TIdHTTP::ResponseText properties).

The TIdHTTP::Response property contains the response code, status line, and headers.

By default, the EIdHTTPProtocolException::ErrorMessage property contains the body content of the HTTP response. Alternatively, if you want to receive the error body content in your TMemoryStream, you can enable the hoNoProtocolErrorException and hoWantProtocolErrorContent flags in the TIdHTTP::HTTPOptions property.

(08-16-2022, 01:23 AM)Boba TC Wrote: For instance:

Just FYI, you should be using System::String instead of AnsiString, and more importantly you are leaking the TMemoryStream if TIdHTTP::Get() or TMemoryStream::SaveToFile() throws an exception. You should protect the TMemoryStream with a try/__finally block, or a RAII wrapper like std::auto_ptr or std::unique_ptr (depending on which compiler you are using).

Messages In This Thread
TIdHTTP error details - by Boba TC - 08-16-2022, 01:23 AM
RE: TIdHTTP error details - by fearcry - 08-16-2022, 01:27 PM
RE: TIdHTTP error details - by rlebeau - 08-16-2022, 07:30 PM
RE: TIdHTTP error details - by Boba TC - 08-20-2022, 04:06 AM
RE: TIdHTTP error details - by Boba TC - 08-20-2022, 11:27 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)