使用喷雾发布应用程序/ x-www-form-urlencoded [英] Posting application/x-www-form-urlencoded using spray
本文介绍了使用喷雾发布应用程序/ x-www-form-urlencoded的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望通过这样的方式提交表格:
I want to "submit a form" through spray like this:
POST / HTTP/1.1
Host: hoge.org
Content-Type: application/x-www-form-urlencoded
username=myid&password=mypw
我知道如何定义 POST
,主机
和 Content-Type
。
关键是如何放置内容( username = ...
。
I know how to define POST
, Host
and Content-Type
.
The thing is how to put the contents (username=...
) in the request.
这是我的代码,等待插入内容:
Here is my code waiting for the insertion of the contents:
//↑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)
}
谢谢!
推荐答案
你可以使用 FormData
marshaller:
You may use FormData
marshaller:
pipe(Post("/", FormData(Seq(
"username" -> "myid",
"password" -> "mypw"))
)) onComplete {
case Success(res) => println("okpk")
case Failure(exc) => println(exc)
}
这篇关于使用喷雾发布应用程序/ x-www-form-urlencoded的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文