2
当密码补助成功的话,在JSON返回的格式,但是当错误返回Laravel 一个HTML格式异常如何以JSON格式使用狂饮在Laravel护照返回错误
当密码补助成功的话,在JSON返回的格式,但是当错误返回Laravel 一个HTML格式异常如何以JSON格式使用狂饮在Laravel护照返回错误
我回答了我自己,加入config to 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);
}