{download a file from the internet put a fully qualified URL into the Edit box http:// etc hit button 1 after the message comes up hit button 2 to save the file somewhere} unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, WinInet; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Button2: TButton; procedure Button1Click(Sender: TObject); procedure GetWebPage(sUrl : string); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; Webpage : string; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); begin GetWebPage(Edit1.Text); end; procedure TForm1.GetWebPage(sUrl : string); var AmtRead : Cardinal; Buffer : array[0..1023] of char; i:integer; SizeString : string; SomeName : string; hHttpSession, hReqUrl : HInternet; Count : integer; begin WebPage := ''; {a big string where the webpage will go} SomeName := 'Web page grabber 1.0'; {whatever ID you want to show up in the servers log} hHttpSession := InternetOpen(PChar(SomeName), {open a handle to the net} INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); try hReqUrl := InternetOpenURL (hHttpSession, PChar(SUrl), {request the url from the net} nil, 0,0,0); try Count := 0; repeat InternetReadFile (hReqUrl, @Buffer, {read file into 1 KB buffer} sizeof (Buffer), AmtRead); If AmtRead <> 0 then begin {code loops through that one last time} If AmtRead = sizeof(Buffer) then WebPage := WebPage + string(Buffer) {store in the big string} else begin {if Amt is less than sizeof(Buffer) on the last go round and you simply append the whole buffer, you will get the end of the file plus whatever crap is left over in the buffer from the previous kilobyte downloaded} for i := 0 to AmtRead - 1 {the length of the last partial read} do Webpage := Webpage + Buffer[i]; {the crude way} end; {else begin} Count := Count + AmtRead; {keep track of the bytes read} SizeString := 'Retrieved ' + IntToStr (Count) + ' of ' + SUrl; {a string you can display of the bytes retrieved} end; {AMTread <> 0} until AmtRead = 0; {the file is downloaded} finally InternetCloseHandle (hReqUrl); end; finally InternetCloseHandle (hHttpSession); end; ShowMessage('Dun'); end; procedure TForm1.Button2Click(Sender: TObject); var f:textfile; begin assignfile(f, 'c:\thatpage.html'); {*****save it somehwere} rewrite(f); Write(f, Webpage); CloseFile(f); end; end. { note that if you want to save the downloaded file to a filestream you can first create a filestream FileStream := TFileStream.Create(afilename, fmOpenWrite or fmCreate); then substitute the following code repeat InternetReadFile (hReqUrl, @Buffer, sizeof (Buffer), AmtRead); FileStream.WriteBuffer(buffer, AmtRead); until AmtRead = 0; to close the file use FileStream.Free; }