delphi 从http 上下载文件的几种方法

  1. 1、利用函数 :
  2. unit downloadTest;  
  3.   
  4. interface  
  5.   
  6. uses  
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  8.   Dialogs, StdCtrls,UrlMon;  
  9.   
  10. type  
  11.   TForm1 = class(TForm)  
  12.     Button1: TButton;  
  13.     procedure Button1Click(Sender: TObject);  
  14.   private  
  15.     { Private declarations }  
  16.   public  
  17.     { Public declarations }  
  18.   end;  
  19.   
  20. var  
  21.   Form1: TForm1;  
  22.   
  23. implementation  
  24.   
  25. {$R *.dfm}  
  26.   //文件下载  
  27. function DownloadFile(Source, Dest: string): Boolean;  
  28. begin   
  29.   try   
  30.     Result :UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;   
  31.     except   
  32.       Result :False;   
  33.     end;   
  34.   end;  
  35.   
  36. procedure TForm1.Button1Click(Sender: TObject);  
  37. var filedir,downloadUrl:string;  
  38. begin  
  39.     filedir :='D:\delphi\download\client.zip';  
  40.     downloadUrl :='http://download.pingan.com.cn/bank/client.zip';  
  41.     if  DownloadFile(downloadUrl,filedir) then  
  42.       showMessage('文件下载成功')  
  43.     else  
  44.       showMessage('文件下载失败');  
  45. end;  
  46.   
  47. end. 

2、用IdHTTP控件吧! 
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;
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值