$client = new Client(['base_uri' => 'http://api.tvmaze.com/']);
$res = $client->request('GET', '/schedule?country=US&date=2014-12-01');
return $res;
返回此错误:
"Class 'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory' not found"
我试过在我的composer.json文件中包含“symfony / psr-http-message-bridge”:“0.2”
首先删除guzzle包:composer remove guzzlehttp/guzzle
然后做:
composer dump-autoload
最后重新安装它:
composer require guzzlehttp/guzzle
还要确保使用guzzle命名空间:
use GuzzleHttp\Client;
那是一个有点老问题。但是,由于答案无法为我解决,所以使用Guzzle Http时最后要尝试一下。
根据Laravel Documentation https://laravel.com/docs/5.3/requests#psr7-requests:
PSR-7标准指定HTTP消息的接口,包括请求和响应。如果您想获取PSR-7请求的实例而不是Laravel请求,您首先需要安装一些库。 Laravel使用Symfony HTTP消息桥组件将典型的Laravel请求和响应转换为PSR-7兼容的实现:
composer require symfony/psr-http-message-bridge
composer require zendframework/zend-diactoros
这解决了我的问题。
您正在实例化一个客户端,但似乎您没有明确表示要实例化的类。试试这个:
$client = new \GuzzleHttp\Client(['base_uri' => 'http://api.tvmaze.com/']);
$res = $client->request('GET', '/schedule?country=US&date=2014-12-01');
return $res;