score:31

Accepted answer

Since post awaits a value that implements the Writeable and ContentTypeOf type classes, you can use the Results.EmptyContent from play.api.mvc. (See API)

So I guess

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

should do. (Didnt test)

score:2

As of Play 2.8, you cannot use the WSRequest.post(body) methods with an empty body, because the BodyWritable trait requires a non-empty Content-Type

Instead, you can do ws.url(u).execute("POST") to send an HTTP POST request with no body.

score:29

For Play 2.6 and after, you have to use play.api.libs.ws.EmptyBody.

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

Typical error is:

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

Related Query

More Query from same tag