laravel 致命错误:使用 Guzzle 6 调用未定义的方法 GuzzleHttp\Client::request()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35236073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined method GuzzleHttp\Client::request() with Guzzle 6
提问by Juliatzin
I'm using Guzzle 6 with Laravel 5.2.
我在 Laravel 5.2 中使用 Guzzle 6。
I'm trying to access a simple internal API:
我正在尝试访问一个简单的内部 API:
use GuzzleHttp\Client;
$client = new Client(['base_uri' => getenv('URL_BASE').'api/v1/']);
$response = $client->request('GET', 'tournaments');
And I get this message:
我收到这条消息:
Fatal error: Call to undefined method GuzzleHttp\Client::request()
When I see the docs, it says:
当我看到文档时,它说:
$client = new GuzzleHttp\Client(['base_uri' => 'https://foo.com/api/']);
But PHPStorm cannot resolve GuzzleHttp
但是 PHPStorm 无法解析 GuzzleHttp
What should I do to make it work???
我该怎么做才能让它工作???
采纳答案by Niklesh Raut
I am also using guzzle, and its working for me, Try like this
我也在使用 guzzle,它对我有用,试试这样
use GuzzleHttp;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
$client = new GuzzleHttp\Client();
And to get response try this
并得到回应试试这个
$response = $client->request('GET', 'tournaments',['query' => ['base_uri' => getenv('URL_BASE').'api/v1/']]);
OR try this if not work
或者尝试这个如果不起作用
$response = $client->request('GET', getenv('URL_BASE').'api/v1/tournaments');