java Post空主体与Jersey 2客户端
我如何与Jersey 2客户提交一个空正文的post请求
final MyClass result = ClientBuilder.newClient()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(What to fill in here if the body should be left empty??, MyClass.class);
更新:此功能:
final MyClass result = ClientBuilder
.newBuilder().register(JacksonFeature).build()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(null, MyClass.class);
# 1 楼答案
只需发布一个空的txt
# 2 楼答案
我发现这对我有用:
传递空字符串,而不是空值
# 3 楼答案
我不知道版本是否改变了它。但是,以下方法不起作用:
builder.put( Entity.json( null ) );
其中,以下各项适用:
builder.put( Entity.json( "" ) );