procedure TUpdateForm.HttpDownLoad(AUrl, AFile: string; BResume: Boolean); var TStream: TFileStream; begin try if FileExists(AFile) then //如果文件已经存在 begin TStream := TFileStream.Create(AFile, fmCreate); end else begin TStream := TFileStream.Create(AFile, fmCreate); end;
try if BResume then //续传方式 begin IdHTTP1.Request.ContentRangeStart := TStream.Size - 1; TStream.Position := TStream.Size - 1; //移动到最后继续下载 IdHTTP1.Head(AUrl); IdHTTP1.Request.ContentRangeEnd := IdHTTP1.Response.ContentLength; end else begin IdHTTP1.Request.ContentRangeStart := 0; //覆盖或新建方式 end;
IdHTTP1.Get(AUrl, TStream); //开始下载 finally FreeAndNil(TStream); end; except on E: Exception do begin WriteLog('IDHTTP.log', Concat('错误信息:', PChar(E.Message))); end; end; end;