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
$client->request()
) instead of using->getBody()->getContents()
, and so then I kept getting confused when I saw these errors because I thought they were talking about a different Guzzle request, but it was just that I was reading a variable from cache expecting it to be a string, and it was really a response object. – Axletree