Dingo API在JSON响应中附加'%'字符

时间:2018-12-24 00:58:55

标签: laravel-5 jwt dingo-api

每当我调用我在Dingo和Laravel 5.7中构建的REST API时,都会得到这个奇怪的结果

curl -X POST 'localhost/api/authenticate' -d "email=admin@example.com&password=secret"

每次我调用此代码时,它都会在JSON响应的末尾附加一个“%”字符,例如

{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC90Z3AtZGVtby5vcGVuYWR1bHQub3JnXC9hcGlcL2F1dGhlbnRpY2F0ZSIsImlhdCI6MTU0NTYxMTg2OSwiZXhwIjoxNTQ1NjE1NDY5LCJuYmYiOjE1NDU2MTE4NjksImp0aSI6InR2M2NkdXpQSDh1VXpmaTgiLCJzdWIiOjEsInBydiI6Ijg3ZTBhZjFlZjlmZDE1ODEyZmRlYzk3MTUzYTE0ZTBiMDQ3NTQ2YWEifQ.pOUN-aiLq-78Rh429gvq3_S77L8gsHIh3oC_Bx41Y60"}%

导致JSON对象无效。它所做的只是简单地调用response-> json方法

/**
 *  API Login, on success return JWT Auth token
 *
 * @param \Illuminate\Http\Request $request
 *
 * @return \Illuminate\Http\JsonResponse
 */
public function authenticate(Request $request)
{
    // grab credentials from the request
    $credentials = $request->only('email', 'password');
    try {
        // attempt to verify the credentials and create a token for the user
        if (!$token = JWTAuth::attempt($credentials)) {
            return response()->json(['error' => 'invalid_credentials'], 401);
        }
    } catch (JWTException $e) {
        // something went wrong whilst attempting to encode the token
        return response()->json(['error' => 'could_not_create_token'], 500);
    }
    // all good so return the token
    return response()->json(compact('token'));
}

我在这里想念东西吗?

ps。这是github存储库的链接:https://github.com/openadult/tgp/blob/df7d6819697801145e4537db8ce8ceec0fe9de9c/app/Http/Controllers/Api/AuthenticateController.php#L18-L32

谢谢!

0 个答案:

没有答案