Skip to content
Advertisement

Guzzle returns stream empty body instead of json body

When I use Postman to make an API call I receive a JSON object..which is what I expected.enter image description here

However When I make same call with Guzzle like so:

JavaScript

I get dump below from Guzzle

JavaScript

Advertisement

Answer

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)

JavaScript

Further reading – Guzzle Responses

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement