How to get the status header for a website programmatically
I am writing a win32 service in Delphi (should be able 开发者_如何学JAVAto translate any other code if you don't know delphi) that needs to fetch the status of a website. I know how to do this in .NET but am not sure with normal windows based programming. So, I need to query a website and return the Status Code 200, 301 ect. My plan is then to parse the data returned and send an email should one of my sites go down.
Can someone lend a hand?
EDIT: This is the code I used in 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;
Take Indy or Synapse library (both are free, indy is included with Delphi, synapse is found on google) and use their HTTP client class to do the job.
精彩评论