HTTPUrlConnection does not download the whole page
I have a problem with this code, as you can see in print, where it
prints the error in the page's code:
public void print(String link) {
String page = this.getPage(link);
// Here I can see the error as it prints the error in the
page's code
System.out.println(page);
System.err.println("1234567890+");
}
public String getPage(String link) {
String pageEscaped = "";
try {
URL url = new URL(link);
// Open the Connection
HttpURLConnection conn = (HttpURLConnection)
url.openConnection();
// Set the information
conn.setRequestProperty("user_agent", "Mozilla/5.0
(Windows; U; Windows NT 6.0; da-DK; rv:1.9.1.4) Gecko/20091016 Firefox/
3.5.4 (.NET CLR 3.5.30729)");
conn.setRequestProperty("max_redirects", "0");
conn.setRequestProperty("timeout", "300");
conn.setRequestMethod("GET");
conn.setDoOutput(true);
// Connect
conn.connect();
// Get the Status-Code and add it to the HashMap
int statusCode = conn.getResponseCode();
String page = this.getPage(conn.getInputStream());
pageEscaped = StringEscapeUtils.unescapeHtml(page);
conn.disconnect();
} catch (IOException e) {System.err.println(e.getCause
());System.err.println(e.getMessage());}
return pageEscaped;
}
public String getPage(InputStream is) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader
(is));
String line = "";
StringBuilder sb = new StringBuilder();
while ((line = br.readLine()) != null) {
sb.append(line+'\n');
System.out.println(line);
}
return sb.toString();
}