Java HTTP Get httpGet(String url)

Here you can find the source of httpGet(String url)

Description

http Get

License

Open Source License

Declaration

public static byte[] httpGet(String url) 

Method Source Code


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

import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;

import java.net.URL;

public class Main {
    public static byte[] httpGet(String url) {
        try {//from  w w w .  ja va2s  . com
            URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            con.setRequestProperty("User-Agent", "Mozilla/5.0");

            InputStream in = con.getInputStream();
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            while (in.available() > 0)
                out.write(in.read());

            in.close();
            out.close();

            return out.toByteArray();
        } catch (IOException e) {
            e.printStackTrace();
            return new byte[] {};
        }
    }
}

Related

  1. doGetRequest(String urlStr)
  2. executeGet(String targetURL)
  3. getHttpURLConnectionByGET(String resourceURL)
  4. getJsonFromUrl(String url)
  5. httpGet(String httpUrl)
  6. httpGet(String url, boolean logStdout)
  7. httpGet(String url, StringBuffer response)
  8. httpGet(String urlStr)
  9. httpGet(String urlStr)