post

open override fun post(body: JsonObject)

Sets the request body as JSON and changes the HTTP method to POST.

This method automatically:

  • Sets the HTTP method to POST

  • Sets Content-Type header to "application/json"

  • Serializes the JSON object as the request body

Note: Calling this method will change the HTTP method to POST if not already set. Use put if you need a PUT request with JSON body.

Parameters

body

The JSON object to set as the body.

See also

For PUT requests with JSON body.

For form-encoded POST requests.


open override fun post(contentType: String, body: String)

Sets the request body with POST method and custom content type.

This method allows specifying a custom Content-Type header along with the body content as a string. Useful for sending non-JSON payloads like XML, plain text, or other custom formats.

Parameters

contentType

The Content-Type header value (e.g., "text/plain", "application/xml").

body

The request body as a string.

See also

For JSON POST requests.