How to get the status header for a website programmatically

I am writing a win32 service in Delphi (should be able to translate any other code if you don't know delphi), which should get the status of a website. I know how to do this in .NET, but I'm not sure about regular Windows-based programming. So I need to request a website and return a status code of 200, 301 ect. My plan is to analyze the returned data and send an email if one of my sites goes down.

Can someone lend a hand?

EDIT: this is the code I used at the end - using the TIDHttp Indy component.

IdHTTP.Get('http://www.example.com');
  if IdHTTP.Connected then begin
     ResponseCode := IntToStr(IdHTTP.ResponseCode);
     ShowMessage(ResponseCode);
  end;
+3
source share
1 answer

Take the Indy or Synapse library (both are free, indy is included in Delphi, the synapse is found on google) and uses its HTTP client to complete the task.

+5
source

Source: https://habr.com/ru/post/1767559/


All Articles