本文整理自网络,侵删。
uses IdHTTP;
//下载主函数
procedure HttpDownLoad(aURL, aFile: string; bResume: Boolean);
var
IdHTTP: TidHttp;
tStream: TFileStream;
begin //Http方式下载
IdHTTP:= Tidhttp.Create(nil);
if FileExists(aFile) then //如果文件已经存在
tStream := TFileStream.Create(aFile, fmOpenWrite) else
tStream := TFileStream.Create(aFile, fmCreate);
if bResume then //续传方式
begin
IdHTTP.Request.ContentRangeStart := tStream.Size - 1;
tStream.Position := tStream.Size - 1; //移动到最后继续下载
IdHTTP.Head(aURL);
IdHTTP.Request.ContentRangeEnd := IdHTTP.Response.ContentLength;
end else //覆盖或新建方式
begin
IdHTTP.Request.ContentRangeStart := 0;
end;
try
IdHTTP.Get(aURL, tStream); //开始下载
finally
tStream.Free;
end;
end;
相关阅读 >>
Delphi研究之驱动开发篇(六)--利用section与用户模式程序通讯(上)
更多相关阅读请进入《Delphi》频道 >>