Skip to content

Instantly share code, notes, and snippets.

@cyberjar09
Created August 29, 2017 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberjar09/b633226338965bd5da6a3fcc09cc412e to your computer and use it in GitHub Desktop.
Save cyberjar09/b633226338965bd5da6a3fcc09cc412e to your computer and use it in GitHub Desktop.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpClient {
public static String getHTML(String urlToRead) throws Exception {
StringBuilder result = new StringBuilder();
URL url = new URL(urlToRead);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
rd.close();
return result.toString();
}
public static void main(String[] args) throws Exception {
String getURL = (args.length == 0) ? "https://graph.facebook.com" : args[0];
System.out.println(getHTML(getURL));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment