如何从 IdHTTP.Get 读取流

How To Read Stream From IdHTTP.Get

HTTP.Request.Connection:= 'Keep-Alive';
HTTP.Request.CacheControl:= 'no-cache';
HTTP.Request.ContentType:= 'application/x-www-form-urlencoded';    
HTTP.Get('jpip://192.168.1.71:3312/cb.jp2?len=4000&type=jpp-stream&cnew=http&tid=0 HTTP/1.1', response);

我想读取响应(我定义为 TStream)。但是我不知道 idHttp.Get 的用法?

如何从服务器获取响应(byte byte)。

您只需要在 TIdHTTP.Get() 的第二个参数中提供一个流。如果要保存到文件,请使用文件流:

var
  Stream: TFileStream;
....
Stream := TFileStream.Create(FileName, fmCreate);
try
  HTTP.Get(..., Stream);
finally
  Stream.Free;
end;

或者如果你想要这样的内存流:

var
  Stream: TMemoryStream;
....
Stream := TMemoryStream.Create;
try
  HTTP.Get(..., Stream);
  Stream.Position := 0; // seek to the beginning of the stream
  // do something with the stream
finally
  Stream.Free;
end;