Java URLConnection Create createConnection(URL url)

Here you can find the source of createConnection(URL url)

Description

Creates a new java.net.URLConnection object from the specified java.net.URL.

License

Open Source License

Exception

Parameter Description

Return

a java.net.URLConnection object for the URL

Declaration

public static URLConnection createConnection(URL url) throws java.io.IOException 

Method Source Code

//package com.java2s;

import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    /**// ww  w  .ja  va  2  s . co m
     * Creates a new <code>java.net.URLConnection</code> object from the 
     * specified <code>java.net.URL</code>.  This is a convenience method 
     * which will set the <code>doInput</code>, <code>doOutput</code>, 
     * <code>useCaches</code> and <code>defaultUseCaches</code> fields to 
     * the appropriate settings in the correct order.  
     * 
     * @return  a <code>java.net.URLConnection</code> object for the URL
     * @throws  java.io.IOException  on input/output errors
     */
    public static URLConnection createConnection(URL url) throws java.io.IOException {
        URLConnection urlConn = url.openConnection();
        if (urlConn instanceof HttpURLConnection) {
            HttpURLConnection httpConn = (HttpURLConnection) urlConn;
            httpConn.setRequestMethod("POST");
        }
        urlConn.setDoInput(true);
        urlConn.setDoOutput(true);
        urlConn.setUseCaches(false);
        urlConn.setDefaultUseCaches(false);
        return urlConn;
    }
}

Related

  1. createConnection(final URL url, final String authValue)
  2. createConnection(String method, String destinationUrl)
  3. createConnection(String processorName, String baseUrl)
  4. createConnection(URL url)
  5. createConnection(URL url)
  6. createConnection(URL url, Proxy proxy)
  7. getURLConnection(String uri)
  8. getUrlConnection(String urlString)