如何在 java-jersey 中执行涉及 JSONObject 的 POST 请求?
How to perform POST request involving JSONObject in java-jersey?
我有以下代码来创建一个 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
里面放什么?
"Inside the post function what exactly should be written."
看看 SyncInvoker
API。查看不同的 post
方法。您将选择其中之一,具体取决于您想要的响应类型。
Entity
argument can simply be written as Entity.json(yourRequestObject)
,自动配置请求为Content-Type:application/json
我有以下代码来创建一个 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
里面放什么?
"Inside the post function what exactly should be written."
看看 SyncInvoker
API。查看不同的 post
方法。您将选择其中之一,具体取决于您想要的响应类型。
Entity
argument can simply be written as Entity.json(yourRequestObject)
,自动配置请求为Content-Type:application/json