如何从Play 2.0的POST中获取有效载荷 [英] How to get payload from a POST in Play 2.0

查看:101
本文介绍了如何从Play 2.0的POST中获取有效载荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用Pla​​y 2.0(Scala)实现REST API,但是我陷入了POST方法.如何从Request对象获取有效负载?我没有找到任何相关文档,也无法从源代码中找出答案.

I'm trying to implement a REST API with Play 2.0 (Scala) but I'm getting stuck in POST method. How do I get the payload from Request object? I haven't find any documentation about it and have been unable to figure out from source code.

推荐答案

您应该能够执行以下操作:

You should be able to do the following:

def index = Action { request =>
  val body = request.body
}

还有类似的东西

def index = Action { request =>
  val name = request.queryString.get("name").flatMap(_.headOption)
  Ok("Hello " + name.getOrElse("Guest"))
}

这篇关于如何从Play 2.0的POST中获取有效载荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆