簡體   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