?
Solved

Capturing a website from Delphi

Posted on 2009-02-17
4
Medium Priority
?
566 Views
Last Modified: 2013-11-23
Is it a fairly simple process to request a website from within a Delphi application and have the resultant webpage or resultant data returned and stored in a variable for further  processing.

e.g.
Send the following
 GET http://www.mywebsite.com/status

Receive the following into a variable
<html><head><title>System Status</title></head><body>Status OK</body></html>

Ideally, it would also be good to capture the header info (e.g. Error 404 or similar)

Thanks
SF
0
Comment
Question by:sheepfarmer
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Hypo earned 2000 total points
ID: 23661724
Hi,
You can use the Indy components that comes with delphi to do that.
Try the code I've attached below, add the units in the uses clause, and then add a button and a memo to the form, and connect the button1Click event to the button.

I don't know what Delphi version you are using, but the example below is made for Delphi6. I know that the Indy components have changed somewhat over the delphi versions, but the functionality will be somewhat like what you see below.

regards
Hypo
uses ..., IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
 
procedure TForm1.Button1Click(Sender: TObject);
var IdHTTPClient : TIdHTTP;
begin
  IdHTTPClient := TIdHTTP.Create(nil);
  try
    Memo1.Text := IdHTTPClient.Get('http://www.google.se');
  finally
    IdHTTPClient.Free;
  end;
end;

Open in new window

0
 

Author Comment

by:sheepfarmer
ID: 23663698
Top banana.  Thanks for this.
Do the Indy HTTP components allow for such things analysis of the returned page, headers etc?
0
 
LVL 12

Assisted Solution

by:Hypo
Hypo earned 2000 total points
ID: 23663804
Sure,
the Indy components have quite alot of good functionality for handeling network communication. You can access the latest headerresponse by reading the IdHTTPClient.Response property. You also have access to the reply code by reading the property IdHTTPClient.ResponseCode.

When using the Indy components, you should be aware that they often throw exceptions when unexpected situations occur. A common example is when you use the TIdTCPServer component, which throws an EConnectionClosedGracefully exception when the client closes a connection before the server does. So It is a good thing to catch such exceptions with try-except blocks, and also to remember that NOT all raised exceptions indicate errors in your code. :)

regards
Hypo
0
 

Author Comment

by:sheepfarmer
ID: 23665044
Thanks for all that - much apprecaited.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question