[Lazarus] Detecting if a remote web server is running

silvioprog silvioprog at gmail.com
Thu Oct 30 12:29:42 CET 2014


On Thu, Oct 30, 2014 at 6:44 AM, Richard Mace <richard.mace at gmail.com>
wrote:

> Hi All,
> What's the most reliable way of detecting whether a remote website is
> responding?
>

Get the HTTP headers:

uses
  fphttpclient;

procedure TForm1.Button1Click(Sender: TObject);
var
  VHttp: TFPHTTPClient;
  VHeaders: TStrings;
begin
  VHttp := TFPHTTPClient.Create(nil);
  VHeaders := TStringList.Create;
  try
    VHttp.RequestHeaders.Add('Connection: Close');
    VHttp.Head('http://lazarus.freepascal.org', VHeaders);
    if VHeaders.Count > 0 then
      ShowMessage('OK')
    else
      ShowMessage('Fail');
  finally
    VHeaders.Free;
    VHttp.Free;
  end;
end;

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20141030/92cc79f5/attachment-0003.html>


More information about the Lazarus mailing list