Java HTTP Read getInputStream(String myUrl)

Here you can find the source of getInputStream(String myUrl)

Description

get Input Stream

License

Open Source License

Declaration

public static InputStream getInputStream(String myUrl) throws IOException 

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.URL;

public class Main {
    public static final int READ_TIMEOUT_MILLIS = 10000;
    public static final int CONNECTION_TIMEOUT_MILLIS = 15000;

    public static InputStream getInputStream(String myUrl) throws IOException {
        InputStream is = null;/*from  www . j  a v a  2  s  .  c om*/
        URL url = new URL(myUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(READ_TIMEOUT_MILLIS /* milliseconds */);
        conn.setConnectTimeout(CONNECTION_TIMEOUT_MILLIS /* milliseconds */);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        // Starts the query
        conn.connect();
        return conn.getInputStream();
    }
}

Related

  1. getData(String urlString)
  2. getHtmlByteArray(final String url)
  3. getHtmlContent(String url)
  4. getInputStream(HttpURLConnection conn)
  5. getInputStream(HttpURLConnection connection)
  6. getInputStream(String url)
  7. getInputStreamFromURL(String urlname)
  8. getInputStreamFromUrl(String urlString)
  9. getInputStreamReader(String httpUrl, int timeout)