TsgcHTTP2ClientMethods › PostFuture

PostFuture Method

Runs an HTTP/2 POST on a background thread and returns a future that resolves to the response body.

Syntax

function PostFuture(const aURL: string; aData: TStream): IsgcFuture<string>;

Parameters

NameTypeDescription
aURLconst stringAbsolute URL that will receive the POST request.
aDataTStreamStream supplying the request body. Keep the stream alive until the future completes; it is read from the background thread while the request is sent.

Return Value

An IsgcFuture<string> that resolves to the response body. Call Await to block until the response arrives, ThenProc to consume the body in a continuation, OnError to handle failures, and Cancel to abort the request.

Remarks

PostFuture is the future-style counterpart of the synchronous Post: the request runs on a background thread and the method returns immediately, so the calling thread is never blocked. Unlike PostAsync, no event handler is required: the response is delivered through the returned future. Calling Cancel disconnects the client, so a request still waiting for its response is aborted instead of running to completion; an aborted or failed request rejects the future with an exception delivered to OnError (or re-raised by Await). Requires Delphi 2010 or later (and C++Builder 2010 or later); it is not available in the .NET edition.

Example

oBody := TStringStream.Create('{"name":"John"}');
oClient.Request.ContentType := 'application/json';
oFuture := oClient.PostFuture('https://api.example.com/users', oBody);
try
  WriteLn(oFuture.Await);
finally
  oBody.Free;
end;

Back to Methods