Delphi XE: idHttp & Request.Range, a bug?

2019-04-14 12:26发布

问题:

I have Delphi XE. I try to set Request.Range of idHttp but I cannot do this. Delphi doesn't allow me to do this neither at design time nor at run time.

E.g. I set '6000-' in a design time -> a property gets empty all time.

I do (in a thread):

Downloader.Request.Range:=(IntToStr(DFileStream.Position) + '-');
synchronize(procedure begin showmessage(Downloader.Request.Range) end); 

showmessage(Downloader.Request.Range) shows me nothing (an empty string).

I checked a request in HTTPAnalyzer -> my program doesn't send a range.

A checked this behavior in Delphi 2010 - all is normal. I set a range in a design/real time. A result is fine in the both cases.

Does anybody have ideas?

Is this a bug or what?

Thanks!

回答1:

The Range property is deprecated instead you must use the the Ranges property.

Check this sample

uses
  IdHTTPHeaderInfo; 

var
  Range: TIdEntityRange;
begin
    Range := FHttp.Request.Ranges.Add;
    Range.StartPos := FRangeFrom;
    Range.EndPos := FRangeTo;
    FHttp.Get(FURL, FileStream);
end;


回答2:

Read this https://forums.embarcadero.com/thread.jspa?messageID=335670

How to set a range in Delphi XE:

idhttp1.Request.Ranges.Add.StartPos:=6000;

It's the same as

idHttp1.Request.Range:='6000-';