Reputation: 961
Play 2.4.x. How can we get the data that is send through the body of POST request as key value pairs? I'm sending a post request from the postman plugin, created a key value parit in the body.
How could I get this value from the action function. I tried with request.body() but it could not get the value alone from it..
Is there any way I cloud get the value that is send in the body of post request
Upvotes: 2
Views: 1607
Reputation: 1751
Try DynamicForm in play's action method.
play.data.DynamicForm data = play.data.Form.form().bindFromRequest();
String username = data.get("username");
String password = data.get("password");
Update:
From Play 2.5 on wards, inject play.data.FormFactory
on your controller it allows you to access form. Reference
@Inject play.data.FormFactory formFactory;
play.data.DynamicForm data = formFactory.form().bindFromRequest();
Upvotes: 6