Java URLConnection Create openConnection(URL localURL)

Here you can find the source of openConnection(URL localURL)

Description

open Connection

License

Apache License

Declaration

private static URLConnection openConnection(URL localURL) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    private static String proxyHost = null;
    private static Integer proxyPort = null;

    private static URLConnection openConnection(URL localURL) throws IOException {
        URLConnection connection;
        if (proxyHost != null && proxyPort != null) {
            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
            connection = localURL.openConnection(proxy);
        } else {/*from ww  w. j  a va 2 s . c o  m*/
            connection = localURL.openConnection();
        }
        return connection;
    }
}

Related

  1. getURLConnection(String uri)
  2. getUrlConnection(String urlString)
  3. getURLConnection(URL url)
  4. openConnection(final URL url)
  5. openConnection(String urlPath)
  6. openConnection(URL url)
  7. openConnection(URL url)
  8. openConnection(URL url)
  9. openConnection(URL url)