【发布时间】:2014-03-28 19:54:41
【问题描述】:
我正在运行 scalatra 2.2 使用 sbt 版本 0.13.0 并使用其内置服务器(码头)。我在 kubuntu 13.10 64 位和我的 java 版本 1.7.0_51 上运行。我正在使用 OpenJDK 64-Bit。在我的示例应用程序中,我可以通过params 获取GET 参数,但我无法获取POST 参数。我检查了request.body,它显示我正在发送这些参数。
我的GET 代码如下所示
get("/requests") {
val typ = params.getOrElse("type", null)
Map(
"success" -> true,
"respones" -> responses.get(typ)
)
}
这行得通。
POST 的代码如下所示
post("/user/register") {
val typ = params.getOrElse("type", null) // here typ is always null even when i send type as formdata
if (typ == null) {
halt(400, Map("type"-> typ, "body"-> request.body.toString))
}
// more code
}
这不起作用。我得到的回应是
{"type":null,"body":"------WebKitFormBoundaryE05sRkwjtB4gBgSW\r\nContent-Disposition: form-data; name=\"type\"\r\n\r\nzombie\r\n------WebKitFormBoundaryE05sRkwjtB4gBgSW--\r\n"}
所以你看到参数type 在请求正文中,但在params 中为空。
我也尝试了this,但我无法让POST 请求工作。有一个github问题here
帮忙?
【问题讨论】: