[英]HTTP POST request as a array of data
我有一個從在線API檢索信息的方法,但是我不確定如何以一些建設性的方式(如數組)檢索此信息。 這是我的代碼:
private void sendPost() throws Exception {
String url = "http://www.imei.info/api/checkimei/";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
String urlParameters = "imei=00000000000000";
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Line: "+inputLine);
}
in.close();
}
它輸出一個字符串,但是該字符串不是任何構造形式:
Testing 2 - Send Http POST request
Line: {"info": {"weight": 130.0, "battery": ["Li-Ion", 2600.0], "qwerty": false, "year":
... 等等
我已從代碼中刪除了我的imei測試信息。
我不確定是否只想保存很多字符串以便以后使用,如果是這種情況,為什么不創建字符串數組並放入變量中呢?
List<String> result= new ArrayList<>();
while ((inputLine = in.readLine()) != null) {
result.add("Line: "+inputLine);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.