phasync
CurlResponse / getBody

Method

CurlResponse::getBody

Return the body stream, without waiting for the transfer.

Description#

public CurlResponse::getBody(): StreamInterface

Reading from the stream waits for data. The stream is read once and cannot be rewound. When the transfer failed, the read that reaches the failure throws a NetworkException (or the ClientException that matches the failure) instead of returning an empty string.

Return values#

StreamInterface

Errors / Exceptions#

ExceptionWhen
ClientExceptionFrom a read, when the transfer failed

Examples#

Example 1
$json = \json_decode((string) $client->get('https://example.com/data.json')->getBody(), true);

See also#