🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #478

DownloadFiles

#478
From: bar
Date: Tue, 04 Mar 2008 10:07
53 lines
2100 bytes
Hi Remy,

I am the following code to download files from the
HTTP server. (BCB 6 and Indy 9.? stable version)

TldHTTP is dropped at design time.
Properties set at design time

ConnectTimeout = 0
HandleRedirects = true

Request
    Connection = Keep-Alive

void TForm1::DownloadFile(String URL,AnsiString FileName)
{
    try
    {
        std::auto_ptr<TFileStream> strm(new TFileStream(FileName,fmCreate));

        HTTP->Request->Pragma = "no-cache";
        HTTP->HandleRedirects = true;
        Application->ProcessMessages();
        HTTP->Get(URL, strm.get());
    }
    catch(const Exception &E)
    {
        ShowMessage(E.Message);
    }
}

I call this function repeatedly with different parameter and its working 
fine.

I have some questions

1.I didn't see any Connect()/Disconnect() function in the code but still 
working. How?. Does it makes difference.
2.Is it good to add these statements when exception occurs.
    catch(const Exception &E)
    {
            if(HTTP->Connected())
                HTTP->Disconnect();
            ShowMessage(E.Message);
    }

Finally i want to use this function in a loop. So i want to know the best 
way to code.

All help greatly appreciated.

Thanks
SA 
Technical Details
Message-ID: <47cd1f44@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,e3fec5dcf86ed,start
X-Google-Attributes: gid11508e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "bar" <shaikakbar250281@yahoo.co.in>
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: DownloadFiles
Date: Tue, 4 Mar 2008 13:07:08 +0300
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 62.150.212.30
Message-ID: <47cd1f44@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1204625220 62.150.212.30 (4 Mar 2008 02:07:00 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail