Using POST routes parameters in Play Framework

一曲冷凌霜 提交于 2019-12-04 02:30:56

Route = resolving params inside the URL = sending params via GET.

That means, that you are trying to send POST request by... GET params... where's the sense ?

James Roper explains that:

At routing time, Play hasn't yet consumed the request body, and so hasn't parsed the submitted form. - and you don't want it to either, because it's your action that decides how/whether the request body gets parsed, streamed, sent elsewhere, if Play did this at routing time, it would limit what you could do in an action.

From security point of view it's definitely bad idea to leave credentials in logs of every machine in the path of client.

Instead you should do it with common form handling way like described in base form documentation:

route:

POST    /v1/accounts/login      controllers.v1.Accounts.login

action:

val userForm = Form(
  tuple(
    "username" -> text,
    "password" -> text
  )
)

def login = Action { implicit request =>
  val (username, password) = userForm.bindFromRequest.get
  Ok("Hello " + username + ", you're trying to login with: " + password)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!