Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object of class GuzzleHttp\Psr7\Request could not be converted to string

I've got an issue for laravel 5.4 when I trying to using guzzleHttp. here is my code.

use GuzzleHttp\Client;
$url = 'http://example.com';
$client = new Client();

$parameter = ['query' => ['name' => 'xxx', 'address' => 'yyy'], 'headers' => [ 'User-Agent' => 'xxxx', 'exceptions' => false, 'timeout' => 10 ]];
$res = $client->request('GET', $url, $parameter);

if ($res->getStatusCode() == 200)
{
 $json = (string)$res->getBody();
 return $json;
}

and I've got this error on log: Error Exception: Object of class GuzzleHttp\Psr7\Request could not be converted to string

what is wrong with my code? please kindly help me. fyi, this error not always happen. sometimes it show this error, sometimes success.

thank you

like image 788
PHP Java Eng Avatar asked Jun 07 '17 04:06

PHP Java Eng


1 Answers

$json = $res->getBody()->getContents();

try this

like image 98
Exprator Avatar answered Oct 19 '22 22:10

Exprator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!