Article View: borland.public.cppbuilder.nativeapi
Article #10612Re: download file from internet
From: Dave
Date: Wed, 31 Mar 2004 14:09
Date: Wed, 31 Mar 2004 14:09
44 lines
2356 bytes
2356 bytes
try the following:
Drop a TIdHTTP component on a new Project and a Button.
On the ButtonClick Event write the following code.
try{
TMemoryStream *File = new TMemoryStream();
IdHTTP1->Get("your url", File);
File->SaveToFile("your file");
}catch(Exception &Except){
ShowMessage("Error occured " + Except.Message);
}
HTH,
David
On Wed, 31 Mar 2004 14:07:59 +0200, ScOe wrote:
> How can i download file from adress like
> http://server/dir1/dir2/dir3/file.ext
>
> i've use InternetOpen, InternetConnect, HttpOpenRequest, InternetReadFile
> but i allways get 0 sized file.
>
> code:
> hInternet = InternetOpen("CBZCommander", INTERNET_OPEN_TYPE_DIRECT,
> NULL, NULL, INTERNET_FLAG_ASYNC);
> Inethandle = InternetConnect(hInternet,"server",
> INTERNET_DEFAULT_HTTP_PORT, NULL,
> NULL, INTERNET_SERVICE_HTTP, NULL, NULL);
> HINTERNET hResource = HttpOpenRequest(Inethandle,
> NULL, "dir1/dir2/dir3/file.ext", NULL, NULL, NULL,
> INTERNET_FLAG_RELOAD, NULL);
> char buf[4096];
> DWORD bytesRead, totalRead = 0, BytesWritten;
> HANDLE hFile = CreateFile("e:\\temp\\downloaded.tmp", GENERIC_WRITE,
> FILE_SHARE_WRITE, NULL,CREATE_NEW, 0, 0);
> if(hFile == INVALID_HANDLE_VALUE){
> ShowMessage("URLDownloadToFileA: Unable to open file for write: "+
> String(GetLastError()));
> }
> else {
> while(InternetReadFile(hResource, &buf, sizeof(buf), &bytesRead)){
> ...
Technical Details
Message-ID:
<bzwd89uwzgcw.16emamhw8bma5.dlg@40tude.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<406ab532@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,3762eecd161977b9 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-03-31 06:10:20 PST From: Dave <dave_xse@-spam-hotmail.com> Subject: Re: download file from internet Newsgroups: borland.public.cppbuilder.nativeapi MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit References: <406ab532@newsgroups.borland.com> Date: Wed, 31 Mar 2004 22:09:27 +0800 Message-ID: <bzwd89uwzgcw.16emamhw8bma5.dlg@40tude.net> User-Agent: 40tude_Dialog/2.0.5.1 NNTP-Posting-Host: 202.72.161.99 X-Trace: newsgroups.borland.com 1080742167 202.72.161.99 (31 Mar 2004 06:09:27 -0800) Lines: 44 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail