我想知道如何在进行http get调用时获取所有数据?我添加了setRequestProperty(“User-Agent”,“Chrome / 30.0.0.0”)和更多数据,但我仍然缺少1/4的数据。
URL site;
HttpURLConnection conn = null;
String result = "";
try {
site = new URL(uri);
conn = (HttpURLConnection) site.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("User-Agent", "Chrome/30.0.0.0");
conn.connect();
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String s = "";
while ((s = reader.readLine()) != null) {
result += s;
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
// Finally disconnect
conn.disconnect();
}