delphi IdHTTP控件断点下载


本文整理自网络,侵删。

 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 image 图像清空

Delphi 控制台读写

firemonkey使用android的路径信息

Delphi 获取安卓手机wifi信息(xe8)

Delphi 程序如何禁止切换输入法?

Delphi做异型窗体png透明

Delphi 限制edit输入 多个例子

Delphi编写iis过滤器实例

Delphi研究之驱动开发篇(六)--利用section与用户模式程序通讯(上)

Delphi tapplication大全

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...