Is there a way to access all request parameters, regardless of HTTP method? I have poured over the documentation and the api without finding a way in Play Framework 2.0.
I have a search on a site that accepts POST and GET. The custom tracking on the site examines all parameters passed in to determine the correct way to store tracking data.
In the Play Framework 1.2.x, I was able to access parameters from a request in a Controller with
request.params.get("keywords")
request.params.get("location")
request.params.all()
With Play Framework 2.0, this is no longer the case. The Request no longer has the method params
, only queryString
and queryString only works with GET and not POST.
It is not feasible to define every single possible tracking parameter into the Controller Action, they are dynamic.
UPDATE: A possible work around is using Body Parsers.
Depending on the content type of the request, the appropriate parser is used, e.g. application/form-url-encoded vs application/json
This is the crude Map that combines POST parameters and GET parameters, with GET parameters taking precedence.
val params: collection.mutable.Map[String, Seq[String]] = collection.mutable.Map()
params ++= request.body.asFormUrlEncoded.getOrElse[Map[String, Seq[String]]] { Map.empty }
params ++= request.queryString
question from:
https://stackoverflow.com/questions/9808348/request-params-is-gone-in-play-framework-2-0 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…