实现文件下载,只需要加入到线程就可以了
2010-03-27 23:19
363 查看
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’); 试试吧,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.sina.com.cn/download/aa.rar',DownLoadFile); DownLoadFile.Free; end;
相关文章推荐
- Java实现Zip压缩文件并可以下载
- Mouse without Borders是微软的一个软件实验项目,这款软件可让鼠标自由在局域网中的多台电脑间移动,键盘输入实现无缝切换,还可以直接用鼠标相互拖拽文件。 如果经常需要同时使用两台以
- Winfrom 线程实现 http、https 文件下载 显示下载进度详情
- 在IIS 7中可以轻松实现文件下载次数统计(转)
- TabActivity可以显示实现多页显示效果,在xml布局文件中需要有一些特殊的配置属性
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 在IIS 7中可以轻松实现文件下载次数统计
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 通过FTP服务端来实现匿名用户和基本用户的访问,可以实现文件上传和下载。通过web网站来浏览内容
- 多个文件开启固定线程等待下载--java实现
- 好象很多人要JB2006的注册文件,我把注册文件提交上来了,需要的人可以直接去下载。
- java实现文件下载的工具类-----------什么都可以下载,只要传入response和文件路径 两个参数
- 超简单快速实现附件上传(各种格式文件)和下载显示(调用浏览器下载后选择可以打开的应用查看)
- ios异步登录,登录的是php写服务器,同理可以实现文件图片下载
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- 这篇文章主要介绍了PHP整合七牛实现上传文件的相关资料,需要的朋友可以参考下
- 用delphi 实现文件下载,可以用于软件的升级
- jsp中实现图片的下载(其他的文件也可以用)
- 用TreeView控件实现资源管理器(显示本地硬盘下所有文件夹和文件,并可以浏览图片)(示例代码下载)
- javaweb之response实现文件下载(文件名是中文名需要经过url编码)