Post empty body with Jersey 2 client
I can't find this in the doc's anywhere, but I believe you can use null
to get an empty body:
final MyClass result = ClientBuilder.newClient()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(Entity.json(null), MyClass.class)
I found that this worked for me:
Response r = client
.target(url)
.path(path)
.queryParam(name, value)
.request()
.put(Entity.json(""));
Pass an empty string, not a null value.