为什么我不能在laravel控制器中使用GuzzleHttp?

时间:2015-04-22 23:06:04

标签: php laravel guzzle

继续收到以下错误:

类Illuminate \ Routing \ Route的对象无法转换为字符串

 $response = $client.post('url', [
                'body' => [
                   'blah' => 'blah'
                ],
                'headers' => [
                    // client id+client secret (base64)
                    'Authorization' => 'Basic sllalalalal='
                ]
            ]);

我没有在任何地方使用路由对象,是数组中所有硬编码的字符串。错误发生的行正好是分号所在的位置。

2 个答案:

答案 0 :(得分:2)

$client.post更改为$client->post。目前,您正在尝试连结$clientpost()

答案 1 :(得分:0)

Guzzle 4

PHP 5.4.x +必需

composer require "guzzlehttp/guzzle" "~4.0"
$client = new \GuzzleHttp\Client();
            $response = $client->post('url', [
                'body' => [
                   'blah' => 'blah'
                ],
                'headers' => [
                    // client id+client secret (base64)
                    'Authorization' => 'Basic sllalalalal='
                ]
            ]);