GuzzleHttp\Psr7\Request类的对象无法转换为字符串

php*_*dev 6 php laravel psr-7 guzzle6 laravel-5.4

当我尝试使用guzzleHttp时,我遇到了laravel 5.4的问题.这是我的代码.

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;
}
Run Code Online (Sandbox Code Playgroud)

我在日志中遇到此错误:错误异常:类GuzzleHttp\Psr7\Request的对象无法转换为字符串

我的代码出了什么问题?请帮助我.fyi,这个错误并不总是发生.有时它会显示此错误,有时会成功.

谢谢

Exp*_*tor 9

$json = $res->getBody()->getContents();
Run Code Online (Sandbox Code Playgroud)

试试这个