TsgcHTTP2ClientMethods › Get

Get Method

Performs a synchronous HTTP/2 GET and blocks until the full response has been received.

Overloads

Overload 1

Syntax

function Get(const aURL: string): string;

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the resource to fetch. Query-string parameters should already be encoded.

Return Value

Response body received from the server decoded as a string. (string)

Remarks

Use this overload when the response is textual (HTML, JSON, XML) and fits comfortably in memory. The method blocks until all DATA frames have been received and returns the concatenated body.

Example

vJSON := oClient.Get('https://api.example.com/v1/users');

Overload 2

Syntax

procedure Get(Const aURL: string; const aResponseContent: TStream);

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the resource to fetch.
aResponseContentconst TStreamCaller-owned stream that receives the raw response bytes as they arrive.

Remarks

Stream-oriented variant intended for binary downloads or large payloads where holding the body as a string is undesirable. The response is written sequentially into aResponseContent (for example a TFileStream).

Example

oStream := TFileStream.Create('image.png', fmCreate);
try
  oClient.Get('https://api.example.com/image.png', oStream);
finally
  oStream.Free;
end;

Back to Methods