0%

Curl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
String[] msgDwnCmds = {"curl", MSG_DOWNLOAD_JSON_URL + "?secret=" + secret + "&device_id=" + device_id};
String msgDwnJson = getResult(msgDwnCmds);
private String getResult(String[] cmds) {
ProcessBuilder pb = new ProcessBuilder(cmds);
pb.redirectErrorStream(true);
Process p;
StringBuilder sb = new StringBuilder();
try {
p = pb.start();
BufferedReader br = null;
String line = null;

br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = br.readLine()) != null) {
System.out.println("\t" + line);
if (line.startsWith("{")) {
sb.append(line + "\n");
}
}

br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}