1,593
社区成员
发帖
与我相关
我的任务
分享
//下载文件
procedure TProgForm.DownFile(fileUrl: string);
var
fileName:string;
tStream: TFileStream;
begin
fileName:='setup' + IntToStr(mForm.lpNode.iSoft_Id) + '.exe'; //从下载路径中获取文件名
if FileExists(fileName) then //如果文件已经存在
tStream := TFileStream.Create(fileName, fmOpenWrite)
else
tStream := TFileStream.Create(fileName, fmCreate);
{if not FileExists(fileName) then //初次下载
begin
idhtp1.Request.ContentRangeStart:=0; //从指定文件偏移处请求下载文件
startIndex:=0;
end
else begin //续传}
try
startIndex:=tStream.Size-1;
if startIndex < 0 then startIndex:=0;
idhtp1.Request.ContentRangeStart := startIndex;
tStream.Position := startIndex ; //移动到最后继续下载
idhtp1.HandleRedirects := true;
idhtp1.Head(fileUrl); //发送HEAD请求
// end;
self.idhtp1.Get(fileUrl,tStream);
except
end;
tStream.Free;
end;