我使用 Java 接收网站的 HTML 内容。但我无法收到它的所有内容。有时,我收到以“...”结尾的内容,而不是内容的结尾。你能告诉我什么是错误。下面是我的代码:
public static String requestHtmlContent(String sUrl){
URL url;
URLConnection connection;
StringBuilder strBuilder = new StringBuilder();
BufferedReader reader;
try {
url = new URL( sUrl );
connection = url.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1");
InputStream is = url.openConnection().getInputStream();
reader = new BufferedReader( new InputStreamReader( is ) );
String line = null;
while((line = reader.readLine())!= null); {
line = reader.readLine();
strBuilder.append(line +"\n");
}
reader.close();
return strBuilder.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return strBuilder.toString();
}