Capturing a website from Delphi

Posted on 2009-02-17
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.

Send the following

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)

Question by:sheepfarmer
    LVL 12

    Accepted Solution

    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.

    uses ..., IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;
    procedure TForm1.Button1Click(Sender: TObject);
    var IdHTTPClient : TIdHTTP;
      IdHTTPClient := TIdHTTP.Create(nil);
        Memo1.Text := IdHTTPClient.Get('');

    Open in new window


    Author Comment

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

    Assisted Solution

    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. :)


    Author Comment

    Thanks for all that - much apprecaited.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    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…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now