使用idHttp下载文件(在线等待)

littlefa 2004-03-21 09:01:40
FFileName:='g:\aaa.zip';
FURL:='http://www.csdn.net/cnshare/soft/openfile.asp?kind=1&id=20520';
if not FileExists(FFileName) then
begin
fHandle := CreateFile(PChar(FFileName), GENERIC_WRITE, FILE_SHARE_WRITE, nil,
CREATE_NEW, 0, 0);
try
FIdHttp.Head(FURL);
FileLength := FIdHttp.Response.ContentLength;
FileSeek(fHandle, FileLength, 0);
finally
FileClose(fHandle);
end;
end;
FFileStream := TFileStream.Create(FFileName, fmOpenWrite or fmShareDenyNone);
FIdHttp.Get(FURL, FFileStream);
在FIdHttp.Head(FURL)时保readtimeout,但我设了1小时
在Get时报'HTTP/1.1 302 Object moved' 到底什么错?
...全文
368 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gdbzh 2004-08-02
  • 打赏
  • 举报
回复
这个代码是说目标已被转移,如果你设置了idhttp允许自动重定向的话就不会报错,它会自动到新目标提取文件
zhengcg 2004-07-30
  • 打赏
  • 举报
回复
该文件确实已经不在了!所以提示这个错误!

还有在使用TIdHTTP时,还会有一个问题,就是只要HTTP的应答码不是 200(OK)的话,就会
出现异常,一出现异常就什么都收不到了(实际数据已经传会本地了的,只是控件没有接收)。但是有不少网站确实也会用 302(Found)作为正常的应答码!这是只能自己去该Indy的相关原代码进行处理了。

注意对于URL本身不是文件URL的(如上例),必须进行两次的GET操作才能获取到文件的(第一次获取到真正的URL,然后才开始下载。
Myattachment 2004-07-29
  • 打赏
  • 举报
回复
我没有用任何控件做了一个文件下载系统epidn,请访问我的私人站点:

http://www.epidn.com/

如果你有什么好的意见和建议,请联系我。我将给你源代码。
zytangzhou 2004-07-29
  • 打赏
  • 举报
回复
给你我做过的一个吧,给我你的邮箱
zhangheaaa 2004-07-29
  • 打赏
  • 举报
回复
使用ftp控件下载目录
作者:aton

delphi中的nmftp控件中Download函数只能下载一个文件,没有提供一个下载整个目录(包含子目录)的函数。

我编写了个实现目录下载功能的方法,需要用到该功能的用户可参考一下。

file://目录下载

function tftp.ex_download(remote_dir,local_dir:string):boolean;

var

i,j,count1:integer;

att,ss:string;

current_dir:string;

temp_dir:string;

begin

try begin

NMFTP1.ChangeDir(remote_dir);

current_dir:=remote_dir;

temp_dir:=copy(current_dir,2,length(current_dir));

if not DirectoryExists(local_dir) then CreateDir(local_dir);

if not directoryexists(local_dir+temp_dir) then createdir(local_dir+temp_dir);

nmftp1.ParseList:=true;

NMftp1.list;

count1:=nmftp1.FTPDirectoryList.name.Count;

for i:=0 to count1-1 do begin

file://必须

NMFTP1.ChangeDir(current_dir);

nmftp1.list;

ss:=nmftp1.FTPDirectoryList.name.Strings[i];

att:=nmftp1.FTPDirectoryList.Attribute.Strings[i];

if (copy(pchar(att),1,1)<>'d')and(copy(pchar(att),1,1)<>'D') then begin

if not DirectoryExists(local_dir) then CreateDir(local_dir);

NMFTP1.Download(current_dir+ss,local_dir+temp_dir+ss);

end

else begin

if not directoryexists(local_dir+temp_dir+ss) then createdir(local_dir+temp_dir+ss);

file://递归调用

ex_download(remote_dir+ss+'\',local_dir);

end;

end;

result:=true;

end

except

On E:Exception do begin

result:=false;

end;

end;

end;

mhhaifeng 2004-07-29
  • 打赏
  • 举报
回复
是不是服务器没有起动

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧