Web services 如何在PlayFramework2/Scala中使用WS-API通过空正文请求进行http post?

Web services 如何在PlayFramework2/Scala中使用WS-API通过空正文请求进行http post?,web-services,scala,rest,playframework-2.0,http-post,Web Services,Scala,Rest,Playframework 2.0,Http Post,我尝试使用Play2/Scala WS-API向服务端点发送一个HTTPPOST请求。由于HTTP POST正文中没有要发送的参数,如何使用 WS.url("http://service/endpoint).post() 我已经尝试了post(),没有任何参数,但它给了我一个错误 无法将单元的实例写入HTTP响应。尝试定义一个 可写[单位] 你能帮忙吗 提前感谢…因为post等待实现Writeable和ContentTypeOf类型类的值, 您可以使用play.api.mvc中的Results

我尝试使用Play2/Scala WS-API向服务端点发送一个HTTPPOST请求。由于HTTP POST正文中没有要发送的参数,如何使用

WS.url("http://service/endpoint).post()
我已经尝试了
post()
,没有任何参数,但它给了我一个错误

无法将单元的实例写入HTTP响应。尝试定义一个 可写[单位]

你能帮忙吗


提前感谢…

因为
post
等待实现
Writeable
ContentTypeOf
类型类的值, 您可以使用
play.api.mvc
中的
Results.EmptyContent
。(见附件)

所以我想

WS.url("http://service/endpoint").post(Results.EmptyContent())

应该这样做。(未测试)

对于Play 2.6及其后版本,必须使用
Play.api.libs.ws.EmptyBody

import play.api.libs.ws.{EmptyBody, WSClient}
WS.url("http://service/endpoint).post(EmptyBody)
典型错误是:

Cannot find an instance of play.api.mvc.Results.EmptyContent to WSBody. Define a BodyWritable[play.api.mvc.Results.EmptyContent] or extend play.api.libs.ws.ahc.DefaultBodyWritables

从播放2.8开始,您不能将
WSRequest.post(body)
方法与空正文一起使用,因为
bodywriteable
特性需要非空的
内容类型


相反,您可以执行
ws.url(u).执行(“POST”)
来发送一个没有正文的HTTP POST请求。

内容类型如何?我仍然得到“无法将play.api.libs.ws.WSBody的实例写入HTTP响应。请尝试定义一个可写的[play.api.libs.ws.WSBody]”。因此,我必须定义一个简单的
bodywriteable[WSBody]
?如何表示无内容类型标题?c、 f。