如何在java-jersey中执行涉及JSONObject的POST请求?

时间:2015-03-04 10:44:37

标签: java http jersey http-post

我有以下代码来创建JSON对象:

Client client = ClientBuilder.newClient();

//response is the value of some GET request I performed before
JSONObject root=new JSONObject(response.readEntity(String.class));  

//url is assigned to URL to which I wanted to POST.
WebTarget target2=client.target(url);

Response response2=target.request(MediaType.APPLICATION_JSON_TYPE);
response2.post(*what goes here*);

我需要在最后post内放入什么?

1 个答案:

答案 0 :(得分:0)

  

"在帖子功能里面究竟应该写什么。"

查看SyncInvoker API。查看不同的post方法。您将根据所需的响应类型选择其中一种。

Entity参数可以简单地写为Entity.json(yourRequestObject),它会自动将请求配置为Content-Type:application/json