Sti*_*ine 28 java jersey jersey-client
如何使用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);
Run Code Online (Sandbox Code Playgroud)
更新:这有效:
final MyClass result = ClientBuilder
.newBuilder().register(JacksonFeature).build()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(null, MyClass.class);
Run Code Online (Sandbox Code Playgroud)
Ald*_*den 23
我无法在任何地方的文档中找到这个,但我相信你可以null用来获得一个空洞的身体:
final MyClass result = ClientBuilder.newClient()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(Entity.json(null), MyClass.class)
Run Code Online (Sandbox Code Playgroud)
小智 9
我发现这对我有用:
Response r = client
.target(url)
.path(path)
.queryParam(name, value)
.request()
.put(Entity.json(""));
Run Code Online (Sandbox Code Playgroud)
传递空字符串,而不是空值.
小智 7
我不知道版本是否改变它.但是,以下不起作用:
builder.put( Entity.json( null ) );
在哪里,以下工作正常:
builder.put( Entity.json( "" ) );
| 归档时间: |
|
| 查看次数: |
27876 次 |
| 最近记录: |