I have a txt uploaded in my site where the content of this txt file is my Noip address that must be consulted by a http request.
The trouble in my code below is that if this file was removed of site, is generated a exception and not is possible execute the folowing lines for function returns a right result.
How solve it?
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
idhttp,
SysUtils;
function GetURLAsString(const aURL, bURL: string): string;
var
lHTTP: TIdHTTP;
a, b: string;
begin
lHTTP := TIdHTTP.Create(nil);
try
a := lHTTP.Get(aURL);
if lhttp.responsecode = 200 then
begin
Result := a
end
else
begin
b := lHTTP.Get(bURL);
if lHTTP.ResponseCode = 200 then
Result := b
else
Result := 'mydnsname.ddns.net';
end;
finally
lHTTP.Free;
end;
end;
begin
try
GetURLAsString('http://www.mysite01.com/conn.txt','http://www.mysite02.com/conn.txt');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
thanks in advance.
EDIT
the result of GetURLAsString must be 'mydnsname.ddns.net' if some of two request fail. Else, the result must be content of txt file uploaded in my site ( that is the same mydnsname.ddns.net ).