TsgcHTTP2Client › Methods › PostAsync
Sends a non-blocking HTTP/2 POST; the response arrives later via the OnHTTP2Response event.
procedure PostAsync(const aURL: string; const aSource: TStream);
| Name | Type | Description |
|---|---|---|
aURL | const string | Absolute URL that will receive the POST request. |
aSource | const TStream | Stream supplying the request body to upload. It is consumed as the frame is written and may be freed once this method returns. |
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.
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;