下面的HTTP转发(futureResponse
函数)会向浏览器返回一个空响应。任何想法有什么不对和/或我应该在哪里看?
val request: WSRequest = ws.url("http://somehost/url2")
val request2: WSRequest = request.withHeaders("Accept" -> "application/json")
val data = Json.obj(
"aaa" -> some_data1,
"bbb" -> some_data2
)
val futureResponse: Future[JsValue] = request2.post(data).map {
response =>
val json= Json.obj(
"ccc" -> "111",
"ddd" -> "222"
)
json
}
Ok(json)
当我在浏览器中收到消息时,响应中的数据为空:
答案 0 :(得分:1)
使操作异步并回复Future [Result],如:
def someAction = Action.async { implicit request =>
val request: WSRequest = ws.url("http://somehost/url2")
val request2: WSRequest = request.withHeaders("Accept" -> "application/json")
val data = Json.obj(
"aaa" -> some_data1,
"bbb" -> some_data2
)
val futureResponse: Future[JsValue] = request2.post(data).map { response =>
val json= Json.obj(
"ccc" -> "111",
"ddd" -> "222"
)
Ok(json)
}
futureResponse
}