Java URL Download get(URL url, String acceptType)

Here you can find the source of get(URL url, String acceptType)

Description

Sends HTTP GET request

License

Open Source License

Parameter

Parameter Description
url the URL to connect to
acceptType the type of data to accept

Exception

Parameter Description
IOException an exception
ProtocolException an exception

Return

Streamed response from server

Declaration

public static InputStream get(URL url, String acceptType) throws IOException, ProtocolException 

Method Source Code


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

import java.io.IOException;
import java.io.InputStream;

import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;

public class Main {
    /**/*  w  ww .  j  av a 2 s.  c o m*/
     * Sends HTTP GET request
     * @param url the URL to connect to
     * @param acceptType the type of data to accept
     * @return Streamed response from server
     * @throws IOException
     * @throws ProtocolException
     */
    public static InputStream get(URL url, String acceptType) throws IOException, ProtocolException {
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setDoOutput(true);
        con.setRequestMethod("GET");
        con.setRequestProperty("accept", acceptType);
        return con.getInputStream();
    }
}

Related

  1. get(String url, String encoding)
  2. get(String urlStr)
  3. get(String urlString)
  4. get(URL host, String endpoint, String customer, String name, String version, OutputStream out)
  5. get(URL url)