我希望通过喷涂“提交表格”:
POST / HTTP/1.1
Host: hoge.org
Content-Type: application/x-www-form-urlencoded
username=myid&password=mypw
我知道如何定义POST
,Host
和Content-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)
}
谢谢!
答案 0 :(得分:3)
您可以使用FormData
marshaller:
pipe(Post("/", FormData(Seq(
"username" -> "myid",
"password" -> "mypw"))
)) onComplete {
case Success(res) => println("okpk")
case Failure(exc) => println(exc)
}