ClientException:客户端错误使用laravel在GuzzleHttp中给出“ 401未经授权”错误

时间:2019-12-04 06:55:21

标签: php laravel guzzle guzzlehttp

我正在尝试使用 GuzzelHttp 发送HTTP请求,但是当我运行它时,出现错误消息:

  

客户端错误:POST http://localhost:8100/api/customers?company_id=9导致401 Unauthorized响应:{“ message”:“未经验证。”

下面是我写的代码:

Route::get('/testguzzel', function() {
    $client = new \GuzzleHttp\Client(); 
    $res = $client->request('POST', 
        'http://localhost:8100/api/customers?company_id=9',
        ['auth' => ['username', 'password'],
        'headers' => ['Accept'=> 'application/vnd.twareeq.v1+json']]);

    return $res->getBody()->getContents();
});

如何解决此问题?

0 个答案:

没有答案