My code:
use GuzzleHttp\Client;
$client = new Client();
$response = $client->post('http://httpbin.org/post', array());
How i can get body response?
getBody not returned response body
echo '<pre>' . print_r($response->getBody(), true) . '</pre>';
GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #80
[size:GuzzleHttp\Psr7\Stream:private] =>
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
You can cast to string
// that will return whole content. seek(0) and then get content
echo '<pre>' . print_r((string)$response->getBody(), true) . '</pre>';
or call method
// this will return remaining content of the stream
echo '<pre>' . print_r($response->getBody()->getContents(), true) . '</pre>';
Thank you!
Thank you! It worked like a charm! @kkopachev
Most helpful comment
You can cast to string
or call method