最佳答案
我自己回答了这个问题,将配置添加到 guzzle 'http_errors' => false
将错误返回到 json。
public function loginapi(Request $request)
{
$username = $request->username;
$password = $request->password;
$http = new Client;
$response = $http->post('http://restapi.dev/oauth/token', [
'form_params' => [
'grant_type' => 'password',
'client_id' => 3,
'client_secret' => 'Lh66IODOP4pZHF676xZA8ghQiIt9OepqYHVzFEIN',
'username' => $username,
'password' => $password,
'scope' => '',
],
'http_errors' => false //add this to return errors in json
]);
return json_decode((string) $response->getBody(), true);
}
关于laravel - 如何使用 Guzzle 以 json 格式返回 Laravel Passport 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43423214/