Created
August 29, 2017 13:08
-
-
Save cyberjar09/b633226338965bd5da6a3fcc09cc412e to your computer and use it in GitHub Desktop.
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
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