Not getting expected response from Guzzle Not getting expected response from Guzzle php php

Not getting expected response from Guzzle


Could be;

$response = $client->send($request)->getBody()->getContents();$response = $client->send($request)->getBody()->read(1024*100000);

This also work as a shorthand;

$response = ''. $client->send($request)->getBody();$response = (string) $client->send($request)->getBody();

// see __toString() method for last examples: http://php.net/manual/en/language.oop5.magic.php#object.tostring


I was having the same issue, and the thing is, if you getBody its a stream, which means it has a pointer, when you do getContents on it its leaving the pointer in the end of the file, which means if you want to get the body multiple times you need to seek the pointer back to 0.

$html1 = $this->response->getBody()->getContents();$this->response->getBody()->seek(0);$html2 = $this->response->getBody()->getContents();$this->response->getBody()->seek(0);

This should work :)

@mrW I hope this helps you


The body that you are var_dumping is a Guzzle stream object. This object can be treated like a string or read from as needed. Documentation for Guzzle Stream here