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

StringdoGET(HttpURLConnection conn)
do GET
conn.setRequestMethod("GET");
return call(conn, null);
StringdoGet(String theURL, Map nameValuePairs)
do Get
String request = validateURL(theURL);
if (nameValuePairs != null && nameValuePairs.size() > 0) {
    if (!request.endsWith("?"))
        request += "?";
    request += encodeParams(nameValuePairs);
URL url = new URL(request);
URLConnection conn = url.openConnection();
...
StringdoGet(String url)
Do GET request
URL localURL = new URL(url);
URLConnection connection = openConnection(localURL);
HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
httpURLConnection.setRequestProperty("Accept-Charset", charset);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader reader = null;
...
StringdoGet(String url, HashMap params)
do Get
String rawJSONString = "";
String getUrl = buildUrl(url, params);
HttpURLConnection connection = (HttpURLConnection) new URL(getUrl).openConnection();
connection.setRequestMethod("GET");
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
...
StringdoGet(String urlStr)
do Get
URL url = null;
HttpURLConnection conn = null;
InputStream is = null;
ByteArrayOutputStream baos = null;
try {
    url = new URL(urlStr);
    conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(TIMEOUT_IN_MILLIONS);
...
StringdoGet(String urlString)
do Get
InputStream is = null;
BufferedReader reader = null;
try {
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("Accept-Charset", "utf-8");
    conn.setRequestProperty("Content-Type", "application/json");
    conn.setConnectTimeout(connectionTimeOut);
...
StringdoGet(URL url, String... args)
_more_
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
for (int i = 0; i < args.length; i += 2) {
    connection.setRequestProperty(args[i], args[i + 1]);
try {
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
    StringBuilder sb = new StringBuilder();
...
StringdoGetRequest(String urlStr)
do Get Request
try {
    URL url = new URL(urlStr);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod("GET");
    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuilder response = new StringBuilder();
    while ((inputLine = in.readLine()) != null) {
...
StringexecuteGet(String targetURL)
execute Get
HttpURLConnection connection = null;
try {
    URL url = new URL(targetURL);
    connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setRequestProperty("Content-Language", "en-US");
    connection.setUseCaches(false);
...
HttpURLConnectiongetHttpURLConnectionByGET(String resourceURL)
Get an object of HttpURLConnection.
HttpURLConnection conn = null;
if (null != resourceURL && !"".equals(resourceURL.trim())) {
    URL url = new URL(resourceURL);
    conn = (HttpURLConnection) url.openConnection();
    conn.setConnectTimeout(5000);
    conn.setRequestMethod("GET");
return conn;
...