我想用delphi 来实现下载 www.xx.com\aa.exe 到我的电脑 c:\ ,下载时并有进度条控件来显示下载的多少?,请问怎么实现?
我想用delphi 来实现下载 www.xx.com\aa.exe 到我的电脑 c:\ ,下载时并有进度条控件来显示下载的多少?,请问怎么实现?
俺给100 分了, 主要是怎样实现 下载文件 www.xx.com\aa.exe 到 我的 c:\ 上! ?急
问题点数:100、回复次数:5Top
1 楼hqhhh(枫叶)回复于 2005-08-02 18:10:50 得分 0
关注:Top
2 楼LocustWei(LocustWei)回复于 2005-08-02 19:09:30 得分 0
其中一段给点提示
//发送get请求,以得到实际的文件数据
FClientSocket.Active:=false;
FClientSocket.Active:=true;
url1:='';
url1:=url1+'GET /'+sSvrFileName+' HTTP/1.1'+#13#10;
url1:=url1+'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*'+#13#10;
url1:=url1+'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)'+#13#10;
//接受数据的范围,可选
if endBytePos<=0 then
begin
url1:=url1+'RANGE: bytes='+inttostr(FPriorPos)+'-'+#13#10;
end
else
begin
url1:=url1+'RANGE: bytes='+inttostr(FPriorPos)+'-'+IntToStr(endBytePos)+#13#10;
end;
//下面这句必须要有
url1:=url1+'Host: '+sSvrHost+#13#10;
url1:=url1+#13#10;
FClientSocket.Socket.SendText(url1);
//头信息处理
while FClientSocket.Active=true do
begin
if FStop=true then
break;
cmd1:=SocketReadLine(FClientSocket.Socket);//取的每一行返回的信息
if pos(lowercase('Content-Range:'),lowercase(cmd1))=1 then
begin//判断是否有找到在确结果,是否可接收
ExistsFile:=true;
end;
if pos(lowercase('Content-Length: '),lowercase(cmd1))=1 then
begin//取文件接收的长度
value1:=copy(cmd1,length('Content-Length: ')+1,length(cmd1));
reclen1:=strtoint(trim(value1));
end;
if cmd1=#13#10 then
break;
end;//end while
Top
3 楼DelphiKey3()回复于 2005-08-03 14:37:14 得分 0
基于上面的原理,写一个ACTIVEX组件,挂一在网页上就OK了,诺顿就是这样做的Top
4 楼SonicX(SonicX)回复于 2006-05-19 21:03:16 得分 0
现成的API
包含在UrlMon单元里
UrlDownLoadToFile,最后个参数可以回调一个过程
function OnProgress(ulProgress, ulProgressMax,ulStatusCode: ULONG; szStatusText: LPCWSTR): HResult;
begin
//Caption:='已下载:' + IntToStr(ulProgress) + '字节'+';总共:' + IntToStr(ulProgressMax)+'字节';
end;Top
5 楼yyjzsl(阿木)回复于 2006-05-19 22:40:10 得分 0
呵呵,路过,顶下。Top




