如何使用Jersey 2客户端提交空机构的帖子请求?
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);
Update: 这个有效:
final MyClass result = ClientBuilder
.newBuilder().register(JacksonFeature).build()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(null, MyClass.class);
5 回答
我可以在任何地方使用't find this in the doc',但我相信你可以使用
null
获得一个空体:我发现这对我有用:
传递空字符串,而不是空值 .
我不知道版本是否会改变它 . 但是,以下不起作用:
builder.put( Entity.json( null ) );
在哪里,以下工作正常:
builder.put( Entity.json( "" ) );
只需发布一个空的txt .
它只对我有用:
所有其他解决方案仍然产生400 Bad Request
附:请求使用MediaType.APPLICATION_JSON完成