简体   繁体   中英

How to send parameters in http post request in for data in laravel

I am trying to authorize user from android device. I integrated the JWT package in my project and made the token based authorization. Here is how my Controller looks like:

    class AdminLoginController extends Controller
     {
    public function __construct()
    {
    $this->middleware('jwt.auth',['except'=>['authenticate']]);
   }

     public function authenticate(Request $request)
      {
       $credentials = $request->only('email', 'password');
       try {
        // 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
        return response()->json(['error' => 'could_not_create_token'], 500);
      }

     // if no errors are encountered we can return a JWT
      return response()->json(compact('token'));
     }

With this i am being to get token for the valid user request but i need to pass the parameters from the parameters section in postman.I have the put on the picture here 邮递员代币生成 . But if i try to post parameters from the body as a form data it says invalid credentials for the same user. How can i solve it. Any kinds of help are appreciated. Thank you.

Fisrt step check:

dd($credentials);

The ouput should be like this:

array:2 [
    "email" => "kajal@gmail.com"
    "password" => "kajal1"
]

Second step check:

dd($token);

And show the ouput.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM