TsgcHTTP2ClientMethods › Post

Post Method

Performs a synchronous HTTP/2 POST, uploading a stream and blocking until the response is received.

Overloads

Overload 1

Syntax

function Post(const aURL: string; const aSource: TStream): string;

Parameters

NameTypeDescription
aURLconst stringAbsolute URL that will receive the POST request.
aSourceconst TStreamStream containing the request body to upload. Its Size sets the content-length pseudo-header.

Return Value

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

Remarks

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.

Example

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

Overload 2

Syntax

procedure Post(const aURL: string; const aSource: TStream; const aResponseContent: TStream);

Parameters

NameTypeDescription
aURLconst stringAbsolute URL that will receive the POST request.
aSourceconst TStreamStream supplying the request payload.
aResponseContentconst TStreamStream that will receive the server's raw response bytes; useful for binary or large replies.

Remarks

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.

Example

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;

Back to Methods