How i can make the Idhttp run in loop if return 404 page not found the problem is 'GOTO CheckAgain' leads into or out of TRY statement
label
CheckAgain;
begin
CheckAgain:
try
idhttp.Get(sURL+WebFile[I], S);
except
on E: EIdHTTPProtocolException do
if AnsiPos('404',E.Message) <> 0 then
begin
I := I+1;
goto CheckAgain;
end;
end;
end;
You have three options:
use a
try/except
block in a loop, catchingEIdHTTPProtocolException
exceptions and checking theirErrorCode
property for 404:if you are using an up-to-date version of Indy, you can enable the
hoNoProtocolErrorException
flag in theTIdHTTP.HTTPOptions
property, and then your loop can remove thetry/except
and check theTIdHTTP.ResponseCode
property instead:use the overloaded version of the
TIdHTTP.Get()
method that has anAIgnoreReplies
parameter, then you can tellGet()
to not raise anEIdHTTPProtocolException
exception on a 404 response: