[英]how to get Body raw JSON data from Postman to Java
在Java中使用Postman不是一個好主意。
但是,您可以使用Java執行相同的操作。
首先,您應該呼叫Postman呼叫的相同端點。 您可以使用Unirest訪問此端點。
Unirest.post("http://api.callme.com/json")
.asJson()
最好觀察在郵遞員上調用的方法,並在Unirest上使用該方法。 在上面的代碼中,我正在使用POST方法。
然后,您將獲得一個JSON對象。
試試這個代碼這是從json數據中獲取數據的基本代碼,請搜索
下載此jar文件json
如何在此處添加jar文件文檔
String url = "http//url"; //define the url here
URL obj; //making the object
obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
//添加授權(如果有)
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();
您應該將內容類型設置為application / json 。 在Java Web應用程序端,您可以從請求中獲取json。 如果使用的是servlet,則必須使用request.getParameter("customer-id");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.