使用喷雾发布应用程序/ x-www-form-urlencoded

时间:2014-09-19 07:44:15

标签: scala http spray

我希望通过喷涂“提交表格”:

POST / HTTP/1.1
Host: hoge.org
Content-Type: application/x-www-form-urlencoded

username=myid&password=mypw

我知道如何定义POSTHostContent-Type 问题是如何将内容(username=...)放入请求中。

这是我的代码,等待插入内容:

//↑boiler plate↑
val pipe = (
  addHeader(Host("hoge.org"))
  ~> addHeader(`Content-Type`(`application/x-www-form-urlencoded`))
  ~> sendReceive.apply
)
pipe(Post("/")) onComplete {
  case Success(res) => println("okpk")
  case Failure(exc) => println(exc)
}

谢谢!

1 个答案:

答案 0 :(得分:3)

您可以使用FormData marshaller:

pipe(Post("/", FormData(Seq(
      "username" -> "myid",
      "password" -> "mypw"))
    )) onComplete {
  case Success(res) => println("okpk")
  case Failure(exc) => println(exc)
}