Java URLConnection Create getURLConnection(String uri)

Here you can find the source of getURLConnection(String uri)

Description

get URL Connection

License

Open Source License

Declaration

public static URLConnection getURLConnection(String uri) throws MalformedURLException, IOException 

Method Source Code


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

import java.io.IOException;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static URLConnection getURLConnection(String uri) throws MalformedURLException, IOException {
        URLConnection urlConn = new URL(uri).openConnection();
        urlConn.setConnectTimeout(120000);
        urlConn.setReadTimeout(120000);// www.j ava  2s.c  o  m
        urlConn.setRequestProperty("User-Agent",
                "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
        return urlConn;
    }
}

Related

  1. createConnection(String processorName, String baseUrl)
  2. createConnection(URL url)
  3. createConnection(URL url)
  4. createConnection(URL url)
  5. createConnection(URL url, Proxy proxy)
  6. getUrlConnection(String urlString)
  7. getURLConnection(URL url)
  8. openConnection(final URL url)
  9. openConnection(String urlPath)