通过 Play WS API 在正文中发送 POST 请求和参数
Send POST request with parameters in body via Play WS API
目前,我正在通过 Play WS API 发送获取请求,如下所示:
wsClient
.url(myUrl)
.withQueryString(getParams(): _*)
.get()
现在我想将此调用更改为使用 HTTP Post。调用以下内容时:
wsClient
.url(myUrl)
.withMethod("POST")
.withBody(getParams(): _*)
.get()
我收到以下错误:
Cannot write an instance of Seq[(String, String)] to HTTP response. Try to define a Writeable[Seq[(String, String)]]
我猜是因为方法 getParams
returns Seq[(String, String)]
.
我该如何解决这个问题?
使用 http post 键值对时使用内容类型 application/x-www-form-urlencoded
发送
这是 posting
的代码
client.url(myUrl)
.withHeaders("Content-type" -> "application/x-www-form-urlencoded")
.post(getParams.map { case (k, v) => s"$k=$v"}.mkString("&"))
目前,我正在通过 Play WS API 发送获取请求,如下所示:
wsClient
.url(myUrl)
.withQueryString(getParams(): _*)
.get()
现在我想将此调用更改为使用 HTTP Post。调用以下内容时:
wsClient
.url(myUrl)
.withMethod("POST")
.withBody(getParams(): _*)
.get()
我收到以下错误:
Cannot write an instance of Seq[(String, String)] to HTTP response. Try to define a Writeable[Seq[(String, String)]]
我猜是因为方法 getParams
returns Seq[(String, String)]
.
我该如何解决这个问题?
使用 http post 键值对时使用内容类型 application/x-www-form-urlencoded
这是 posting
的代码 client.url(myUrl)
.withHeaders("Content-type" -> "application/x-www-form-urlencoded")
.post(getParams.map { case (k, v) => s"$k=$v"}.mkString("&"))