One API is Urldownloadtofile. In addition, some of the Delphi controls can be easily downloaded, such as Nmhttp, specifying nmhttp1.inputfilemode: = Ture; Specifies that the body is a local file name and that a get is available for download.
Uses UrlMon;
function DownloadFile (Source, dest:string): Boolean;
Begin
Try
Result: = Urldownloadtofile (nil, PChar (source), PChar (Dest), 0, nil) = 0;
Except
Result: = False;
End
End
If DownloadFile (' Http://www.borland.com/delphi6.zip, ' c:\kylix.zip ') then
ShowMessage (' Download succesful ')
else ShowMessage (' Download unsuccesful ')
========================
Routines:
Uses URLMon, Shellapi;
function DownloadFile (sourcefile, destfile:string): Boolean;
Begin
Try
Result: = Urldownloadtofile (Nil, PChar (sourcefile), PChar (DestFile), 0, nil) = 0;
Except
Result: = False;
End
End
Procedure TForm1.Button1.Click (Sender:tobject);
Const
URL Location
SourceFile: = ' http://www.google.com/intl/de/images/home_title.gif ';
Where to save the file
DestFile: = ' c:\temp\google-image.gif ';
Begin
If DownloadFile (sourcefile, DestFile) Then
Begin
ShowMessage (' Download succesful! ');
Show downloaded image in your browser
ShellExecute (Application.handle,pchar (' Open '), PChar (DestFile), PChar (""), Nil,sw_normal)
End
Else
ShowMessage (' Error while downloading ' + sourcefile)
End
=================
Add the following code:
NMHTTP1. Inputfilemode: = ture;
NMHTTP1. Body: = ' local filename ';
NMHTTP1. Header: = ' Head.txt ';
NMHTTP1. Outputfilemode: = FALSE;
NMHTTP1. Reportlevel: = Status_basic;
NMHTTP1. Proxy: = "IP address of proxy server";
NMHTTP1. ProxyPort: = "Port number of the proxy server";
With NMHTTP1. HeaderInfo do
Begin
Cookie: = "";
Localmailaddress: = "";
Localprogram: = "";
Referer: = "";
UserID: = ' user name ';
Password: = ' user password ';
End;
NMHTTP1. Get (' Http://www.abcdefg.com/software/a.zip ');
Try it, there are examples of tnmhttp controls in the Delphi directory. nt4+,win95+,ie3+, you can use the URL moniker function.
Uses URLMon;
...
Olecheck (Urldownloadtofile (Nil, ' URL ', ' Filename ', 0,nil));
One of the last parameters you can also pass in a IBindStatusCallback implementation to track the download progress or control abort the download. Simple occasion a word will be done.
BTW, URL moniker encapsulates most URLs, rather than encapsulating protocols like nmhttp, so you can download http,ftp even local and LAN files with Urldownloadtofile, and other custom moniker, such as MSITStore (documentation moniker implementation of the MSDN library).
Var
Downloadfile:tfilestream;
Beginio
Downloadfile:=tfilestream.create (' C:\aa.rar ', fmcreate);
Idhttp1.get (' Http://www.sina.com.cn/download/aa.rar ', DownLoadFile);
Downloadfile.free;
End
http://blog.csdn.net/zang141588761/article/details/51934072
Delphi implementation of several methods of file download (three ways to use controls)