TsgcHTTP2Client | HTTP/2 ファイルダウンロード

クライアントがサーバーからファイルをリクエストする場合、OnHTTP2Response イベントを使用してストリームレスポンスを読み込みます。

 

大容量ファイルのダウンロード

大きなファイル(数百 MB 以上)をダウンロードする場合は、デフォルトの 60 秒タイムアウトで転送が中断されないよう、HTTP2Options.ReadTimeout0(タイムアウトなし)に設定してください:

 


oClient := TsgcHTTP2Client.Create(nil);
oClient.HTTP2Options.ReadTimeout := 0; // no timeout for large files
oClient.Get('https://server/largefile', oStream);

 


oClient := TsgcHTTP2Client.Create(nil);
oClient.OnHTTP2Response := OnHTTP2ResponseEvent;
oClient.Get('https://http2.golang.org/file/gopher.png');
...
procedure OnHTTP2ResponseEventEvent(Sender: TObject; const Connection: TsgcHTTP2ConnectionClient; 
  const Request: TsgcHTTP2RequestProperty; const Response: TsgcHTTP2ResponseProperty)
begin
  oStream := TFileStream.Create('file', fmOpenWrite or fmCreate);
  Try
    oStream.CopyFrom(Response.Data, Response.Data.Size);
  Finally
    oStream.Free;
  End;
end;