Java HTTP Request getRequest(String urlString)

Here you can find the source of getRequest(String urlString)

Description

get Request

License

Open Source License

Declaration

public static String getRequest(String urlString) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class Main {
    public static String getRequest(String urlString) {
        StringBuilder result = new StringBuilder();
        URL url = null;/*  w  w  w.j  av  a  2s . com*/
        BufferedReader rd = null;
        HttpURLConnection conn = null;
        try {
            url = new URL(urlString);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            if (url != null) {
                conn = (HttpURLConnection) url.openConnection();
            }
            if (conn != null) {
                conn.setRequestMethod("GET");
                rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            }

            String line;
            assert rd != null;
            while ((line = rd.readLine()) != null) {
                result.append(line);
            }
            rd.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return result.toString();
    }
}

Related

  1. addRequestProperties(final Map requestProperties, final HttpURLConnection connection)
  2. doHttpRequest(String action, URL url, String body, String... args)
  3. getContent(String requestUrl)
  4. getDataFromRequestViaPost(String request, String urlParameters)
  5. getOutputFromUrlConnection(String stringUrl, String requestProperty)
  6. getRequest(URL url, int timeout)
  7. getRequestContent(String urlText)
  8. makeUrlRequest(String surl, String data, String method)
  9. request(boolean quiet, String method, URL url, Map body)