简体   繁体   中英

Using Entity.json for sending JSONObject to server

I am new to jersey Rest API and got stuck with use of Entity.json() method. I am using Entity.json(obj) to request post call, but I am not sure how should I get the obj at server side. here is my example code

Client side :

JSONObject obj = new JSONObject("{"testing":"check"}");
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target("http://localhost/test/postcall");
Response res = target.request(MediaType.APPLICATION_JSON).post(Entity.json(obj));

Server Side

@POST
@Path("/postcall")
public Response()
{
   return Response.status(200).entity("post called").build();
}

I am not sure what param I should used to get the JSONObject passed from client to my server side code.

Used

Entity.entity(obj.toString(),"application/json"),

and at server side got as a String parameter ,

public Response(String input)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM