RESTapi登录问题

时间:2018-03-15 09:35:54

标签: php rest laravel-5

我有以下登录API。

public function login() {
        if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
            $user = Auth::user();
            $success['token'] = $user->createToken('MyApp')->accessToken;
            $agency = new AgencyResource(Agency::find($user->agency_id));
            $success['agency'] = $agency;
            return response()->json(['responseCode' => '101', 'responseMessage' => 'Login successful', 'data' => $success], $this->successStatus);

        } else {
            return response()->json(['responseCode' => '102', 'responseMessage' => 'Invalid username or password', 'data' => null], 401);
        }
    }

每当我用错误的凭据登记邮递员时,我都会收到以下回复。

{
    "responseCode": "102",
    "responseMessage": "Invalid username or password",
    "data": null
}

哪个是对的。但是同样的api在Android设备上给出了以下响应,而不是json格式。

   Result in Failure:
[Failure: Exception : HTTP Exception 401 Unauthorized]

问题:我需要回复邮递员的回复。请帮忙

我使用laravel 5.5

0 个答案:

没有答案