TsgcHTTP3Client › Methods › Post

Post Method

Sends a synchronous HTTP/3 POST request with a request body.

Syntax

Post(const aURL, aData: string; const aContentType: string): string string overload

function Post(const aURL: string; const aData: string;

  const aContentType: string = 'application/x-www-form-urlencoded'): string; overload;
NameTypeDescription
aURLconst stringAbsolute URL of the target resource.
aDataconst stringRequest body. It is encoded as UTF-8 before being sent in the HTTP/3 DATA frame.
aContentTypeconst stringValue of the content-type request header. Defaults to application/x-www-form-urlencoded.

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

Post(const aURL: string; const aSource, aResponseContent: TStream) stream overload

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

  const aResponseContent: TStream); overload;
NameTypeDescription
aURLconst stringAbsolute URL of the target resource.
aSourceTStreamStream read in full from position 0 and sent as the request body. May be nil to send an empty body.
aResponseContentTStreamStream that receives the response body.

None. The response body is written to aResponseContent.

Remarks

The call blocks the calling thread until the complete response has been received. When the client is not connected yet, the URL is used to open the QUIC connection first. For a non-blocking request use PostAsync, which delivers the reply on OnResponse.

POST submits data to the target resource, typically to create a record or to invoke a server-side action. The string overload encodes aData as UTF-8 and defaults aContentType to application/x-www-form-urlencoded, so pass application/json explicitly when posting JSON.

The stream overload always sends content-type: application/octet-stream. It does not accept an aContentType parameter, so when the server requires a specific media type use the string overload instead.

Example



vBody := '{"name": "John"}';

vResponse := oClient.Post('https://api.example.com/v1/users', vBody,

  'application/json');

Back to Methods