发布应用程序/ x-WWW窗体-urlencoded采用喷(Posting application/

2019-10-21 00:04发布

我想通过这样的喷雾“提交表单”:

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)
}

谢谢!

Answer 1:

您可以使用FormData编组:

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


文章来源: Posting application/x-www-form-urlencoded using spray
标签: scala http spray