从指定的java.net.URL创建一个新的java.net.URLConnection对象。
/* 来自 *时 代 J a v a 公 众 号*/ //package com.nowjava; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; public class Main { /** * 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(