![]() |
Indy Response Body bei EIdHTTPProtocolexception auswerten
Hallo!
Ich habe das Problem, dass ich mit Indy einen PUT-Request an einen REST-Service absetze. Wenn an dem Request etwas nicht stimmt, antwortet der Server mit einem HTTP-Statuscode 400 (Bad Request). Soweit auch noch ok. Der TIdHTTP jedoch wirft dann jedoch eine EIdHTTPProtocolexception und gibt den Responsebody nicht zurück. Den bräuchte ich aber, weil darin in JSON-Form Details zum aufgetretenen Fehler enthalten sind. Jemand eine Idee, wie ich in diesem Fall an den Responsebody kommen kann? Grüße Cody |
AW: Indy Response Body bei EIdHTTPProtocolexception auswerten
Hmm..
über die HTTPOptions: (Auszug aus nem Source, bei dem ich auch selber machen will)
Delphi-Quellcode:
(Verwende D6 mit Indy 10.6.2.0)
var
O : TIdHTTPOptions; ... // Damit wir selber den ErrorCode verarbeiten können. O := Http.HTTPOptions; include(O, hoNoProtocolErrorException); include(O, hoWantProtocolErrorContent); Http.HTTPOptions := O; |
AW: Indy Response Body bei EIdHTTPProtocolexception auswerten
Zitat:
Delphi-Quellcode:
FHTTP.HTTPOptions := FHTTP.HTTPOptions + [hoNoProtocolErrorException, hoWantProtocolErrorContent];
Aber leider leider: FHTTP.Put liefert dann zwar keine Exception mehr, aber auch keinen Inhalt im Rückgabestring. Es ist aber Inhalt da, das habe ich mit apitester.com geprüft. EDIT: Fehler gefunden. Dein Hinweis war richtig, nur wurden die HTTPOptions an anderer Stelle noch mal überschrieben. Funktioniert und Problem gelöst. Danke dir! |
AW: Indy Response Body bei EIdHTTPProtocolexception auswerten
oder ohne die options zu verändern, indem man einen Handler für die EIdHTTPProtocolException schreibt in dem man auf die ErrorMessage zugreifen kann:
Delphi-Quellcode:
Quelle:
try
... except on E: EIdHTTPProtocolException do begin WriteLn(E.Message); WriteLn(E.ErrorMessage); end; on E: Exception do begin WriteLn(E.Message); end; end; ![]() |
AW: Indy Response Body bei EIdHTTPProtocolexception auswerten
MessageBody <> ErrorMessage! Ersteres enthält JSON-Daten, letzteres "Bad Request". Aber siehe Edit oben: Problem gelöst.
|
AW: Indy Response Body bei EIdHTTPProtocolexception auswerten
Zitat:
|
AW: Indy Response Body bei EIdHTTPProtocolexception auswerten
Bei mir stand in der E.ErrorMessage das Bad Request drin, E.Message war leer. Aber egal, mit den Options funktioniert es wunderbar. Den Fehlercode cann ich ja genauso gut über TIdhTTP.ResponseCode abfragen.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:11 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz