TsgcHTTP2Client | HTTP/2 Download File

Quando il client richiede un file al server, utilizzare l'evento OnHTTP2Response per caricare la risposta dello stream.

 

Download di file di grandi dimensioni

Quando si scaricano file di grandi dimensioni (centinaia di MB o più), impostare HTTP2Options.ReadTimeout su 0 (nessun timeout) per garantire che il trasferimento venga completato senza essere interrotto dal timeout predefinito di 60 secondi:

 


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;