Created
January 29, 2012 22:14
-
-
Save JayKid/1700991 to your computer and use it in GitHub Desktop.
[Java] Get Html Content from a Url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getHtmlContent(String url) throws Exception, IOException { | |
HttpClient client = new DefaultHttpClient(); | |
HttpGet request = new HttpGet(url); | |
HttpResponse response = client.execute(request); | |
String html = ""; | |
InputStream in = response.getEntity().getContent(); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); | |
StringBuilder str = new StringBuilder(); | |
String line = null; | |
while((line = reader.readLine()) != null) | |
{ | |
str.append(line); | |
} | |
in.close(); | |
html = str.toString(); | |
return html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment