TsgcHTTP2ClientMethods › PostAsync

PostAsync Method

Sends a non-blocking HTTP/2 POST; the response arrives later via the OnHTTP2Response event.

Syntax

procedure PostAsync(const aURL: string; const aSource: TStream);

Parameters

NameTypeDescription
aURLconst stringAbsolute URL that will receive the POST request.
aSourceconst TStreamStream supplying the request body to upload. It is consumed as the frame is written and may be freed once this method returns.

Remarks

Returns immediately after the request has been scheduled on the HTTP/2 session. Because HTTP/2 multiplexes many streams over a single connection, several async calls may be in flight at once; assign an OnHTTP2Response handler before invoking this method to collect the replies.

Example

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

Back to Methods