Here you can find the source of get(URL url, String acceptType)
Parameter | Description |
---|---|
url | the URL to connect to |
acceptType | the type of data to accept |
Parameter | Description |
---|---|
IOException | an exception |
ProtocolException | an exception |
public static InputStream get(URL url, String acceptType) throws IOException, ProtocolException
//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(); } }