CURL到Guzzle有Header问题

时间:2015-08-18 22:23:38

标签: php curl guzzle

我正在尝试在guzzle上设置Authorization标头。我的请求成功使用了以下CURL代码:

public function __construct()
    {
        $this->config = \Config::get('services.******');

        $this->client = new Client([
            'base_uri' => 'https://*******/' . $this->config['merchant_id']
        ]);
    }

    public function getInventoryItems()
    {
        $response = $this->client->get('items', [
            'headers' => [
                'Authorization' => 'Bearer' . $this->config['token']
            ]
        ]);

        return json_decode($response->getBody());
    }

我怎么能用这个Guzzle代码获得401。我试图以不同的方式设置标题而没有运气。

{{1}}

1 个答案:

答案 0 :(得分:3)

'Authorization' => 'Bearer' . $this->config['token']

应该是

'Authorization' => 'Bearer ' . $this->config['token']