Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi IdHTTP Exception verhindern (https://www.delphipraxis.net/119453-idhttp-exception-verhindern.html)

kng 26. Aug 2008 22:12


IdHTTP Exception verhindern
 
Hallo,

Ich würde gerne wissen, ob es eine Möglichkeit gibt zu verhindern, dass die IdHTTP Komponente eine Exception wirft, wenn ein Server einen Statuscode ungleich 2xx bzw. 3xx zurückliefert und stattdessen trotzdem die Antowort des Servers liefert, ohne extra einen Exception Handler zu entwerfen.

Klartext: Wenn ein Server nicht erreichbar ist, soll es eine Exception geben und wenn nicht, die Antwort vom Server, egal ob 200 OK oder 404 Not Found.

Ich hoffe, ich wurde verstanden. Danke.

HalloDu 26. Aug 2008 22:13

Re: IdHTTP Exception verhindern
 
Was spricht gegen einen Exceptionhandler ala TRY...EXCEPT...END; Der würde im Prinzip doch erfüllen was du willst.

kng 26. Aug 2008 22:18

Re: IdHTTP Exception verhindern
 
Zitat:

Zitat von HalloDu
Was spricht gegen einen Exceptionhandler ala TRY...EXCEPT...END; Der würde im Prinzip doch erfüllen was du willst.

Folgendes Gebilde:
Delphi-Quellcode:
try
  idhttp1.Get('http://google.de/abc.txt');
except
  showmessage(idhttp1.ResponseText);
end;
liefert:
Zitat:

HTTP/1.1 301 Moved Permanently
aber ich würde gerne die komplette Antwort vom Server haben, also das hier:
Zitat:

HTTP/1.1 301 Moved Permanently
Location: http://www.google.de/abc.txt
Content-Type: text/html; charset=UTF-8
Date: Tue, 26 Aug 2008 21:17:20 GMT
Expires: Thu, 25 Sep 2008 21:17:20 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 225

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
here.
</BODY></HTML>
Oder geht das mit den Indy Komponenten nicht? :?

Dani 26. Aug 2008 22:20

Re: IdHTTP Exception verhindern
 
Du könntest den Parameter AIgnoreReplies versuchen.

Delphi-Quellcode:
procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt);

kng 26. Aug 2008 22:27

Re: IdHTTP Exception verhindern
 
Zitat:

Zitat von Dani
Du könntest den Parameter AIgnoreReplies versuchen.

Delphi-Quellcode:
procedure Get(AURL: string; AResponseContent: TStream; AIgnoreReplies: array of SmallInt);

Gute Idee, aber folgendes:
Delphi-Quellcode:
showmessage(idhttp1.Get('http://google.de/abc.txt', [301]));
liefert zwar keine Exception, aber dafür einen leeren String. :cry:


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:45 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz