2016-03-08 64 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,而另一個則是系統上的實際內容。 –