The author needs to write a function of downloading files in the system that the author recently developed. I used to call the API before using BCB. I suddenly remembered that there was an API to get it, so I came to search early. This API is URLDOWNLOADTOFILE. Not only that, some controls of Delphi can also be easily downloaded, such as nmhttp, specify nmhttp1.inputfilemode: = TURE; specifying Body as a local file name, specifying Get can be downloaded. Here are the detailed code, all from 9cbs. I all sort it here so that everyone is convenient.
================= = Urlmon; Function Downloadfile: Boolean; Begin Try Result: = URLDOWNLOADTOFILE (NIL, PCHAR (SOURCE), PCHAR (DEST) , 0, NIL) = 0; Except Result: = FALSE; END;
IF Downloadfile ('http://www.borland.com/delphi6.zip,' c: / kylix.zip ') Then ShowMessage (' Download unsuccesful ') Else ShowMessage
========================= 例:
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? 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 Download " Sourcefile) End;
================= Add to the following code:
NMHTTP1.InputFileMode: = ture; NMHTTP1.Body: = 'local file'; NMHTTP1.Header: = 'Head.txt'; NMHTTP1.OutputFileMode: = FALSE; NMHTTP1.ReportLevel: = Status_Basic; NMHTTP1.Proxy: = 'Agent The server's IP address'; nmhttp1.proxyport: = 'proxy server port number'; with nmhttp1.headerinfo DO
Begincookie: = '; localmailaddress: ='; localprogram: = '; referer: ='; userid: = 'user name'; password: = 'user password'; end;
NMHTTP1.GET ('http://www.abcdefg.com/software/a.zip');
Try it, there is an example of TNMHTTP control in Delphi's 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 get into an IbindStatusCallback implementation to track download schedule or control abort. A simple occasion is done.
- Reply to get 0--
BTW, URL Moniker encapsulates most URLs, not like NMHTTP, so you can download HTTP, FTP, even local files and local area network files with UrldownloadTofile, and other Custom Moniker, such as MsitStore (MSDN Library Document Moniker implementation) ).
============ Use the IDHTTP control! 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;
// ---------------------------
Program end