Download, pause and resume a download using tnethttpclient1
#3
بارك الله فيك اطلعت عليه سابقا لكن كنت اريد كود اكثر وضوحا وجدت كود بسيط يعتمد على Tidhttp قمت بتحويله لكن توقفت عند هذا السطر لم اعرف مقابله في tnethttpclient

idhttp.Request.Range := IntToStr(f.Position) + '-'+  IntToStr(aRangeEnd);

كود :
procedure Download(Url,LocalFile:String;   WorkBegin:TWorkBeginEvent;Work:TWorkEvent;WorkEnd:TWorkEndEvent); var   Http: TIdHTTP;   exit:Boolean;   FLength,aRangeEnd:Integer; begin   Http  := TIdHTTP.Create(nil);   fFileStream:=nil;   try     try       Http.OnWork:= Work;       Http.OnWorkEnd := WorkEnd;       Http.Head(Url);       FLength := Http.Response.ContentLength;       exit:=false;       repeat         if not FileExists(LocalFile) then begin           fFileStream := TFileStream.Create(LocalFile, fmCreate);         end         else begin           fFileStream := TFileStream.Create(LocalFile, fmOpenReadWrite);           exit:= fFileStream.Size >= FLength;           if not exit then             fFileStream.Seek(Max(0, fFileStream.Size-4096), soFromBeginning);         end;         try           aRangeEnd:=fFileStream.Size + 50000;           if aRangeEnd < fLength then begin                      Http.Request.Range := IntToStr(fFileStream.Position) + '-'+  IntToStr(aRangeEnd);           end           else begin             Http.Request.Range := IntToStr(fFileStream.Position) + '-';             exit:=true;           end;           Http.Get(Url, fFileStream);         finally           fFileStream.Free;         end;     until exit;     Http.Disconnect;     except       on E : Exception do       Begin       //Result:=False;       //AddLog(E.Message);       end;     end;   finally     Http.Free;   end; end;
الرد


الردود في هذا الموضوع
RE: Download, pause and resume a download using tnethttpclient1 - بواسطة invocker - 14-05-2021, 06:09 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم