=
uses UrlMon;
function DownloadFile(Source, Dest: ): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;
DownloadFile('http://www.borland.com/delphi6.zip, 'c:\kylix.zip') then
ShowMessage('Download succesful')
ShowMessage('Download unsuccesful')
例程:
Uses URLMon, ShellApi;
function DownloadFile(SourceFile, DestFile: ): 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/l/de/images/home_title.g';
// Where to save the file
DestFile := 'c:\temp\google-image.g';
begin
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
ShowMessage('Error while downloading ' + SourceFile)
end;
=
加入如下代码:
NMHTTP1.InputFileMode := ture;
NMHTTP1.Body := '本地文件名';
NMHTTP1.Header := 'Head.txt';
NMHTTP1.OutputFileMode := FALSE;
NMHTTP1.ReportLevel := Status_Basic;
NMHTTP1.Proxy := '代理服务器IP地址';
NMHTTP1.ProxyPort := '代理服务器端口号';
With NMHTTP1.HeaderInfo do
Begin
Cookie := '';
LocalMailAddress := '';
LocalProgram := '';
Referer := '';
UserID := '用户名称';
Password := '用户口令';
End;
NMHTTP1.Get(‘http://www.abcdefg.com/software/a.zip’);
试试吧Delphi目录中有TNMHTTPControl控件例子NT4+,Win95+,IE3+,你可以用URL Moniker功能
uses URLMon;
...
OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));
其中最后个参数你还可以传入个IBindStatusCallback实现以跟踪下载进度或控制中止下载简单场合句话就搞定了
--回复得分 0--
BTW, URL Moniker封装了大多数URL而不是像NMHTTP那样封装协议因此你可以用URLDownloadToFile下载HTTPFTP甚至本地文件和局域网文件还有其他custom moniker比如MSITSTORE(MSDN Library文档moniker实现)
用IdHTTPControl控件吧!
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;
//---------------------------
结束
最新评论