我希望我的Spray客户端发送包含此内容类型的帖子请求
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')
我做错了什么?感谢帮助者。
答案 0 :(得分:1)
您基本上已经回答了自己的问题 - 您需要坚持使用FormData。但是有几件小事: