Scala中Play框架中的路由问题:如何防止URI中的任何查询字符串参数?

问题描述 投票:1回答:1

这是我的原始路线:

http://localhost:9000/test

我想避免在原始路由中出现任何其他查询字符串参数。例如:

http://localhost:9000/test?a=1
http://localhost:9000/test?b=1
http://localhost:9000/test?c=1
http://localhost:9000/test?d=1&e=2
http://localhost:9000/test?f=1&g=2&h=3
...

所有这些都不在请求中,如果有的话,响应必须是BadRequest(400)。

scala playframework routing
1个回答
0
投票

您可以编写一个控制器来检查请求中是否有参数,如果传递了任何参数,则返回BadRequest,例如:

 def endpoint = Action { request =>
   if (request.queryString.isEmpty) {
     Ok("Valid request")
   } else {
     BadRequest ("Arguments are not allowed")
   }
  }
© www.soinside.com 2019 - 2024. All rights reserved.