2016-03-08 108 views
0

我正在使用"guzzlehttp/guzzle": "~6.0"并尝试使用下面的代码github用户。Laravel:GuzzleHttp客户端

$client = new \GuzzleHttp\Client(); 

$request = $client->createRequest('GET', 'https://api.github.com/users'); 
$query = $request->getQuery(); 
$query->set('since',135); 
$response = $request->send(); 
$oResponse = json_decode($response->getBody(true)); 

但我得到错误 Argument 3 passed to GuzzleHttp\Client::request() must be of the type array, string given 但是这种方法适用于"guzzle/guzzle": "^3.9",我不知道在哪里,我失去了一些东西。

回答

0

"guzzlehttp/guzzle": "~6.0"会让你的Guzzle v6.1.1。 v3.9和v6.1之间的方法和方法签名不相同。以至于Client::createRequest()在v6.1中不存在,实际上被Client::__call()捕获,然后传递到Client::request(),因为您提供的参数与Client::request()的签名不匹配,从而导致错误。

有关Guzzle 6的更多信息可从Guzzle docs获取。

您还会发现您的$request->send()会引发错误。 Guzzle 6将Psr7放在心上,因此Request/Response对象实现了Psr7规范。

+0

这是非常好的技术信息,可以解释为什么会遇到错误,但它不能提供有关解决问题的快速解决方案。你能扩展这个答案吗? – dctucker

+0

版本不匹配。开发一个API,而另一个则是系统上的实际内容。 –