繁体   English   中英

使用Entity.json将JSONObject发送到服务器

[英]Using Entity.json for sending JSONObject to server

我是jersey Rest API的新手,因此无法使用Entity.json()方法。 我正在使用Entity.json(obj)请求后调用,但是我不确定如何在服务器端获取obj。 这是我的示例代码

客户端 :

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

我不确定应该使用什么参数来将JSONObject从客户端传递到服务器端代码。

用过的

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

在服务器端得到了String参数,

public Response(String input)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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