[英]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.