用Delphi实现文件下载的几种方法


本文整理自网络,侵删。

 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')


*************************************************************************************************

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;



*************************************************************************************************

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');


*************************************************************************************************

uses URLMon;

...

OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));


*************************************************************************************************

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;


*************************************************************************************************

相关阅读 >>

Delphi 把mp3做背景音乐

Delphi android 安卓系统 关闭打开(显示隐藏)输入法

Delphi 多函数形式的多线程同步-线程执行顺序

Delphi http post json示例

Delphi启动/停止windows服务,启动类型修改为"自动"

Delphi中组件panel、splitter、groupbox、按钮组件(checkbox...)、计时器、滚动条、多选卡

Delphi andorid应用程序检查wifi有效还是无效

Delphi 从url地址中获得文件名

Delphi 判断奇数偶数

Delphi xe5 for android 退出提示

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    暂无评论...