Guzzle returns stream empty body instead of json body
getBody()
returns a stream. If you want to get all the content at once you can use getContents()
method and decode json while at it (if you need to)
$payload = json_decode($response->getBody()->getContents());
Further reading - Guzzle Responses
If $response->getBody()->getContents()
doesn't work for you, try:
$response->getBody()->__toString();
As mentioned here, sometimes getContents
's stream pointer is already at the end of stream and then it returns empty response, but __toString
resets it by default.