【发布时间】:2015-10-21 12:15:28
【问题描述】:
我希望我的 Spray Client 使用此内容类型发送帖子请求
Content-Type: application/x-www-form-urlencoded
我相信我需要为此使用对象 FormData:
var fD = new FormData(Seq("UserID:" -> "123", "PWD" -> "123" , "Brand" -> "123"))
但我愿意接受其他解决方案。
编辑:
我试过这样发送:
implicit val system = ActorSystem("Client")
var fD = FormData(Map("UserID" -> "123", "PWD" -> "123" , "Brand" -> "123"))
import system.dispatcher // execution context for futures below
val log = Logging(system, getClass)
log.info("Sending test Msg")
val pipeline = sendReceive ~> unmarshal[FormData]
var startTimestamp = System.currentTimeMillis()
val responseFuture = pipeline {
Post(url, fD)
}
responseFuture.onComplete(x=> println(s"Request completed in ${System.currentTimeMillis() - startTimestamp} millis.\n" +
s"Recived :"+x.get)
)
我得到了这个错误:
spray.httpx.PipelineException: UnsupportedContentType(Expected 'application/x-www-form-urlencoded')
我做错了什么?感谢帮助。
【问题讨论】:
标签: scala http spray form-data