TsgcHTTP2Client › Methods › Post
Performs a synchronous HTTP/2 POST, uploading a stream and blocking until the response is received.
function Post(const aURL: string; const aSource: TStream): string;
| Name | Type | Description |
|---|---|---|
aURL | const string | Absolute URL that will receive the POST request. |
aSource | const TStream | Stream containing the request body to upload. Its Size sets the content-length pseudo-header. |
Response body received from the server decoded as a string. (string)
Use this overload for textual exchanges such as JSON or form data where the full response can be returned as a string. Configure Request.ContentType before calling to advertise the body's media type.
oBody := TStringStream.Create('{"name":"John"}');
try
oClient.Request.ContentType := 'application/json';
vResponse := oClient.Post('https://api.example.com/users', oBody);
finally
oBody.Free;
end;
procedure Post(const aURL: string; const aSource: TStream; const aResponseContent: TStream);
| Name | Type | Description |
|---|---|---|
aURL | const string | Absolute URL that will receive the POST request. |
aSource | const TStream | Stream supplying the request payload. |
aResponseContent | const TStream | Stream that will receive the server's raw response bytes; useful for binary or large replies. |
Fully stream-based variant: both the request payload and the server response are handled through TStream instances, avoiding the overhead of a string conversion on either side. Prefer this overload for file uploads that return binary payloads.
oIn := TFileStream.Create('upload.bin', fmOpenRead);
oOut := TMemoryStream.Create;
try
oClient.Post('https://api.example.com/upload', oIn, oOut);
finally
oOut.Free;
oIn.Free;
end;