TsgcHTTP2ClientMethods › Connect

Connect Method

Establishes the HTTP/2 session and performs a blocking GET to the supplied URL.

Overloads

Overload 1

Syntax

function Connect(const aURL: string): string;

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the target resource. The scheme (https / http) selects between TLS-secured h2 and cleartext h2c.

Return Value

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

Remarks

This overload opens the TCP/TLS transport, performs the ALPN/Upgrade negotiation, issues the initial GET request and returns once the entire response has been read. Use it when you need the full payload in memory as a string.

Example

vResponse := oClient.Connect('https://api.example.com/status');

Overload 2

Syntax

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

Parameters

NameTypeDescription
aURLconst stringAbsolute URL of the target resource used by the first HTTP/2 request.
aResponseContentconst TStreamCaller-supplied stream that receives the response body; the position is advanced as bytes are written. Useful for large payloads or direct file output.

Remarks

This streaming overload behaves identically to the string-returning variant but writes the response directly to the supplied TStream, avoiding intermediate string allocation. Prefer it when the response does not need to be held in memory.

Example

oStream := TFileStream.Create('out.bin', fmCreate);
try
  oClient.Connect('https://api.example.com/download', oStream);
finally
  oStream.Free;
end;

Back to Methods