phasync
HttpClient / put

Method

HttpClient::put

Send a PUT request with a body.

Description#

public HttpClient::put(
    UriInterface|string $url,
    mixed $requestData,
    HttpClientOptions|array|null $options = null
): ResponseInterface

Takes the body and the options like HttpClient::post.

Parameters#

$url UriInterface|string
The URL to put to
$requestData mixed
The body: a string, a stream, an array or an object
$options HttpClientOptions|array|null = null
Options for this request only

Return values#

ResponseInterface

Errors / Exceptions#

ExceptionWhen
InvalidArgumentExceptionFor an option name that does not exist
RuntimeExceptionFor a headers entry without a colon, and for array or object data with a Content-Type other than application/x-www-form-urlencoded or application/json

Examples#

Example 1
$response = $client->put('https://example.com/items/7', \json_encode(['name' => 'x']), [
    'headers' => ['Content-Type: application/json'],
]);

See also#