| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3043 人关注过本帖, 2 人收藏
标题:[分享]Delphi网络下载文件
只看楼主 加入收藏
yangguofa
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2004-5-5
收藏(2)
 问题点数:0 回复次数:1 
[分享]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')

搜索更多相关主题的帖子: 网络 Delphi 文件 下载 分享 
2004-05-09 14:47
yangguofa
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2004-5-5
收藏
得分:0 
例程:

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.';
  // 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.’);

试试吧,Delphi的目录中有TNMHTTP控件的例子。NT4+,Win95+,IE3+,你可以用URL Moniker的功能。

uses URLMon;

...

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

其中最后一个参数你还可以传入一个IBindStatusCallback的实现以跟踪下载进度或控制中止下载。简单的场合一句话就搞定了。

--回复得分 0--

BTW, URL Moniker封装了大多数URL,而不是像NMHTTP那样封装协议,因此你可以用URLDownloadToFile下载HTTP,FTP甚至本地文件和局域网文件,还有其他的custom moniker,比如MSITSTORE(MSDN Library的文档moniker实现)。

============
用IdHTTP控件吧!
var
  DownLoadFile:TFileStream;
beginio
  DownLoadFile:=TFileStream.Create('c:\aa.rar',fmCreate);
  IdHTTP1.Get('http://www.',DownLoadFile);
  DownLoadFile.Free;
end;

//---------------------------

程序结束

/bbs/UploadFile/2005-3/2005320191459674.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://www./bbs/UploadFile/2005-3/2005320191459674.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2004-05-09 15:46
快速回复:[分享]Delphi网络下载文件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011496 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved