Java Utililty Methods HTTP Get

List of utility methods to do HTTP Get

Description

The list of methods to do HTTP Get are organized into topic(s).

Method

StringreadURL(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();
...
StringreadUrl(HttpURLConnection conn)
read Url
Scanner scanner = new Scanner(conn.getInputStream());
StringBuilder sb = new StringBuilder("");
while (scanner.hasNext()) {
    sb.append(scanner.nextLine());
return sb.toString();
StringreadUrl(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;
...
StringreadURL(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 {
...
StringreadUrl(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) {
...
StringrequestGetMethod(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');
...