如何从Postman到Java获取Body原始JSON数据

如何从Postman到Java获取Body原始JSON数据,java,json,api,servlets,postman,Java,Json,Api,Servlets,Postman,我有变量customer id和JSON格式的原始数据中的值。我想从postman得到java的值。我如何实现它 在Java中使用Postman不是一个好主意 但是你可以用Java做同样的事情 首先,您应该调用Postman调用的相同端点。您可以使用访问此端点 Unirest.post("http://api.callme.com/json") .asJson() 观察在Postman上调用的方法和在Unirest上使用相同的方法是很好的。在上面的代码中,我使用的是POST方法 然后,

我有变量customer id和JSON格式的原始数据中的值。我想从postman得到java的值。我如何实现它


在Java中使用Postman不是一个好主意

但是你可以用Java做同样的事情

首先,您应该调用Postman调用的相同端点。您可以使用访问此端点

Unirest.post("http://api.callme.com/json")
    .asJson()
观察在Postman上调用的方法和在Unirest上使用相同的方法是很好的。在上面的代码中,我使用的是POST方法


然后,您将得到一个JSON对象。

您应该将内容类型设置为application/JSON。在java web应用程序端,您可以从请求中获取json。如果您使用的是servlet,那么您必须使用
request.getParameter(“客户id”)

请尝试此代码 这是从json数据获取数据的基本代码,请搜索

下载这个jar文件

如何添加jar文件文档

//如果您有任何授权,请添加授权

con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept-Language", "UTF-8");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
JSONObject jsonObject = new JSONObject(response.toString());
String nid = jsonObject.get("customer-id").toString();

从邮递员到Java?您的意思是从Postman调用Java的端点开始?首先,使用一些http库,例如:。其次,看一下-这将帮助您处理JSON对象
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept-Language", "UTF-8");
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
JSONObject jsonObject = new JSONObject(response.toString());
String nid = jsonObject.get("customer-id").toString();