Java URL Connection sendGetRequest(String urlStr)

Here you can find the source of sendGetRequest(String urlStr)

Description

send Get Request

License

Open Source License

Declaration

public static String sendGetRequest(String urlStr) 

Method Source Code


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

import java.io.BufferedReader;

import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static String sendGetRequest(String urlStr) {
        try {/* ww  w  .  j av a  2 s  .c o m*/
            URL url = new URL(urlStr);
            URLConnection conn = url.openConnection();
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = rd.readLine()) != null) {
                sb.append(line);
            }
            rd.close();
            return sb.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. retrieveData(URL url)
  2. retrieveFromUrl(String url, boolean useCache, boolean deleteOnExit)
  3. retrieveHtml(URLConnection http)
  4. scanPackageByJar(List> classes, final String packageName, final URL jarUrl, final boolean recursive)
  5. sendGetRequest(String resourceUrl, String contentType)
  6. sendPost(String url, String param)
  7. setTimeout(URLConnection conn, int milliseconds)
  8. setTimeouts(URLConnection connection)
  9. shortenUrl(String url)