如何从IdHTTP.Get读取流

时间:2015-03-20 09:50:13

标签: delphi indy

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用法?

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

1 个答案:

答案 0 :(得分:1)

您只需要在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;