TIdHttp no ResponseContent on bad request - 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 no ResponseContent on bad request (/thread-2505.html) |
TIdHttp no ResponseContent on bad request - fpctuxe - 09-14-2021 Hello, 1. with the TIdHTTP i has problems on Rest- Server. Sends the Server on Bad Request (400, 404) the Client doesn’t received the ResponseContent. I look and found a little workaround. I advanced IdHttp.pas Definition: TIdCustomHTTP = class(TIdTCPClientCustom) private FRestMode: Boolean; //Add procedure SetRestMode(AValue: Boolean); //Add public property RestMode: Boolean read FRestMode write SetRestMode; //Add Implementation: procedure TIdCustomHTTP.SetRestMode(AValue: Boolean); //Add begin if FRestMode=AValue then Exit; FRestMode:=AValue; if FRestMode then begin HTTPOptions:= HTTPOptions + [hoNoProtocolErrorException]; end else begin HTTPOptions:= HTTPOptions - [hoNoProtocolErrorException]; end; end; function TIdHTTPProtocol.ProcessResponse(AIgnoreReplies: array of Int16): TidHTTPWhatsNext; else begin //From case if not FHttp.FRestMode then begin //Add CheckException; Result := wnJustExit; Exit; end; //Add end; maybe that will help the users too 2. I have seen, you're working on Indy OpenSSL 1.1.1, very nice, thanks. My question. When will the new Indy library be added to the Lazarus library. Thanks for support. RE: TIdHttp no ResponseContent on bad request - rlebeau - 09-14-2021 (09-14-2021, 07:33 PM)fpctuxe Wrote: with the TIdHTTP i has problems on Rest- Server. Sends the Server on Bad Request (400, 404) the Client doesn’t received the ResponseContent. Yes, it does, just not where you are expecting it to be. By default, TIdHTTP raises an EIdHTTPProtocolException for any HTTP error, where the response content will be in the EIdHTTPProtocolException.ErrorMessage property. As you have already noted, you can enable the hoNoProtocolErrorException option to avoid this exception. There is also a hoWantProtocolErrorContent option available, which you seem to have missed (see https://www.indyproject.org/2016/01/10/new-tidhttp-flags-and-onchunkreceived-event/). (09-14-2021, 07:33 PM)fpctuxe Wrote: I look and found a little workaround. That workaround is not necessary, and I will not be incorporating something like that into the main code. The same effect can be achieved by simply enabling the hoNoProtocolErrorException and hoWantProtocolErrorContent options together. No need to modify ProcessResponse() at all. (09-14-2021, 07:33 PM)fpctuxe Wrote: When will the new Indy library be added to the Lazarus library. Indy has been available in Lazarus' Online Package Manager for awhile, and is kept up-to-date with GIT updates. RE: TIdHttp no ResponseContent on bad request - fpctuxe - 09-15-2021 1. I have tested with the HttpOptions hoNoProtocolErrorException and hoWantProtocolErrorContent It works on rest- server as required. This is the better way. Thanks. 2. In the Lazarus Online Package Manager is currently the version 10.6.2.3911. Is in this version OpenSSL 1.1.1 integrated? RE: TIdHttp no ResponseContent on bad request - rlebeau - 09-16-2021 (09-15-2021, 05:55 PM)fpctuxe Wrote: In the Lazarus Online Package Manager is currently the version 10.6.2.3911. No, because that new code has not been incorporated into Indy's main code yet, it is still a Work-In-Progress. |