为Http Post播放框架Scala代理 [英] Play Framework Scala Proxy For Http Post

查看:184
本文介绍了为Http Post播放框架Scala代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩游戏!框架与scala并尝试为http请求创建代理,GET和POST。

I'm using play! framework with scala and trying to create a proxy for http requests, GET and POST.

GET操作似乎正在运行,问题在于POST操作,我在哪里'我无法传递请求的有效负载。

The GET actions seems to be working, the issue is with the POST action, where I'm not able to pass the payload of the request.

我尝试了几件事,比如下面的代码,但似乎都没有。

I tried several things, like the code below, but none seems to be working.

  def postAction(query: String) = Action.async { implicit request =>
    val data = if (request.body.asText != None) request.body.asText.get else ""
    WS.url(DEMO_URL + query).post(data).map(resp => Ok(resp.body).as("application/json"))
  }

最后要提到的是我对这两个人都很陌生!和scala。

Last thing to mention is that I'm new to both play! and scala.

推荐答案

我不得不添加 parse.json 动作.async(parse.json)

I had to add parse.json the Action.async(parse.json)

现在代码更加简单,看起来像这样:

The code now is much simpler and looks like this:

  def postAction(query: String) = Action.async(parse.json) { implicit request =>
    WS.url(DEMO_URL + query).post(request.body).map(resp =>
      Ok(resp.body).as("application/json")
    )
  }

这篇关于为Http Post播放框架Scala代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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