2014-08-30 113 views
0

我是新来的泽西Rest API,并使用Entity.json()方法卡住了。我正在使用Entity.json(obj)来请求post调用,但我不知道如何在服务器端获取obj。这里是我的示例代码使用Entity.json发送JSONObject到服务器

客户端:

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)); 

服务器端

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

我不知道什么PARAM我应该用来获取JSONObject的从客户端传递到我的服务器端代码。

+0

那么在此得到了与JAXB呢? – laune 2014-08-31 17:37:33

回答

0

使用

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

,并在服务器端得到了作为字符串参数,

public Response(String input)