Use the HEAD method, remembering that if the answer is not 200 (ok), the routine will fall into exception and this should be treated.
Follow example as requested in the question:
procedure TForm1.Button1Click(Sender: TObject);
var
http : TIdHttp;
url : string;
codigo : integer;
begin
url := 'http://www.xxx.com.br/teste.php?Teste';
http := TIdHTTP.Create(nil);
try
try
http.Head(url);
codigo := http.ResponseCode;
except
on E: EIdHTTPProtocolException do
codigo := http.ResponseCode;
end;
ShowMessage(IntToStr(codigo));
finally
http.Free();
end;
end;
Remembering that to bring up the word OK, just make use of a case in the variable code. For this, follows HTTP response code list
This method as is returns the source code of the page. If (and only if) the OP is using the latest version of Indy, it could get what you requested with the command
http.Get(LINK, nil);
, but for the method to work in older versions of Indy, I think it is better to use the head method.– Filipe.Fonseca
@Sunstreaker, it did not work out, he of the Forbiden error, the address for true TEST is: http://www.escritoriocontatos.com.br/teste.php?LETRA
– user7605
@Filipe.Fonseca, he gave Forbiden error in his too. See address http://www.escritoriocontatos.com.br/teste.php?LETRA
– user7605
@user7605 test character only, temporarily remove your htaccess from folder / and try again.
– Filipe.Fonseca
@Fonseca, just removed and tested again, it appears in the showmessage the code 403. But I’ve checked everything, ta tudo certo....
– user7605
@Sunstreaker the method still takes the "display source code" for Indy9. On reading, sensational workaround!
– Filipe.Fonseca
Perfect @Sunstreaker, thanks!
– user7605
@Sunstreaker, this way we can make some test when the link falls it generate a message, type LINK OUT OF AIR!
– user7605