我正在尝试使用 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();
});
如何解决此问题?