![]() |
TIdHTTP error details - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Indy (https://www.atozed.com/forums/forum-8.html) +--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html) +--- Thread: TIdHTTP error details (/thread-2840.html) |
TIdHTTP error details - Boba TC - 08-16-2022 Dear All; when TIdHTTP::Get method throws out an EIdHTTPProtocolException, where do I find details of the error? For instance: Code: TIdHTTP *IdHTTP; RE: TIdHTTP error details - fearcry - 08-16-2022 1) Did you URL-Encode your AnsiString before use it in Idhttp->Get() ? 2) Is there possibly a Consent Page between your Target URL ? That would be an Explanation for this. cheers fearcry RE: TIdHTTP error details - rlebeau - 08-16-2022 (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). RE: TIdHTTP error details - Boba TC - 08-20-2022 (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? RE: TIdHTTP error details - Boba TC - 08-20-2022 (08-16-2022, 07:30 PM)rlebeau Wrote: 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....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). Thank you, Remy. Thank you, Remy. Thank you, Remy. |