List of utility methods to do HTTP Get
String | readURL(final String textURL) Read string from URL. final StringBuilder text = new StringBuilder(128); try { final URL url = new URL(textURL); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(2 * 1000); connection.setRequestMethod("GET"); connection.setRequestProperty("User-Agent", "config-reader"); connection.connect(); ... |
String | readUrl(HttpURLConnection conn) read Url Scanner scanner = new Scanner(conn.getInputStream()); StringBuilder sb = new StringBuilder(""); while (scanner.hasNext()) { sb.append(scanner.nextLine()); return sb.toString(); |
String | readUrl(String url, String token) read Url URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("GET"); if (token != null) { con.setRequestProperty("X-Auth-Token", token); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; ... |
String | readURL(String url, String type) Read the contents of the specified URL and store it in a string. HttpURLConnection.setFollowRedirects(false); HttpURLConnection conn = null; BufferedReader ins; StringBuilder outs = new StringBuilder(); char[] buffer = new char[1024]; String contents = ""; int tmpi; try { ... |
String | readUrl(String urlAsString, int timeout) read Url URL url = new URL(urlAsString); HttpURLConnection hConn = (HttpURLConnection) url.openConnection(); hConn.setReadTimeout(timeout); hConn.setConnectTimeout(timeout); return readInputStream(hConn.getInputStream()); |
byte[] | readURL(URL url) read URL HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); int code = connection.getResponseCode(); if (code > HttpURLConnection.HTTP_OK) { handleError(connection); InputStream stream = connection.getInputStream(); if (stream == null) { ... |
String | requestGetMethod(String url, String... params) Makes a GET method to an URL. url = encodeURLGET(url, params); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestMethod("GET"); StringBuilder builder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { String line; while ((line = reader.readLine()) != null) { builder.append(line).append('\n'); ... |