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 关闭自己,重新运行

Delphi crc算法的实现

Delphi中的进制转换

Delphi getsessionusername通过会话id得到会话名称

Delphi 在消息窗口中显示进度条

Delphi 实现代码重启android app

Delphi 中文字符串截取

Delphi 取bmp图片宽高

Delphi网络英汉字典代码

解决Delphi程序在非中文系统下乱码

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



打赏

取消

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

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

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

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

评论

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