List of utility methods to do URLConnection Create
HttpURLConnection | createConnection(final URL url, final String authValue) Creates a new HTTP connection to the specified server. final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(0); connection.setReadTimeout(0); connection.setRequestMethod("GET"); connection.setRequestProperty("Authorization", authValue); connection.setDoOutput(true); return connection; |
HttpURLConnection | createConnection(String method, String destinationUrl) create Connection URL url = null; HttpURLConnection httpConn = null; int code = -1; try { try { String queryString = getQueryString(); if (!queryString.equals("")) { destinationUrl = destinationUrl + "?" + queryString; ... |
HttpURLConnection | createConnection(String processorName, String baseUrl) create Connection HttpURLConnection connection = (HttpURLConnection) new URL(baseUrl + "api/process/" + processorName) .openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); return connection; |
URLConnection | createConnection(URL url) create Connection URLConnection con = url.openConnection(); con.addRequestProperty("Protocol", "HTTP/1.1"); con.addRequestProperty("Connection", "keep-alive"); con.addRequestProperty("Keep-Alive", "200"); con.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1"); return con; |
URLConnection | createConnection(URL url) Creates a new java.net.URLConnection object from the specified java.net.URL .
URLConnection urlConn = url.openConnection(); if (urlConn instanceof HttpURLConnection) { HttpURLConnection httpConn = (HttpURLConnection) urlConn; httpConn.setRequestMethod("POST"); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); ... |
String | createConnection(URL url) create Connection URLConnection connection = url.openConnection(); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36"); connection.addRequestProperty("Content-Type", "application/json"); connection.addRequestProperty("Content-Encoding", "gzip"); connection.addRequestProperty("Accept", "application/json"); ... |
HttpURLConnection | createConnection(URL url, Proxy proxy) create Connection HttpURLConnection con = (HttpURLConnection) url.openConnection(proxy); con.setRequestProperty("User-Agent", "Hello Minecraft!"); con.setDoInput(true); con.setUseCaches(false); con.setConnectTimeout(15000); con.setReadTimeout(15000); return con; |
URLConnection | getURLConnection(String uri) get URL Connection URLConnection urlConn = new URL(uri).openConnection(); urlConn.setConnectTimeout(120000); urlConn.setReadTimeout(120000); 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; |
URLConnection | getUrlConnection(String urlString) get Url Connection URL url = new URL(urlString); URLConnection con = url.openConnection(); return con; |
URLConnection | getURLConnection(URL url) Returns a URL connection that an input stream can be obtained from. if (url == null) { throw new MalformedURLException("URL specified is null"); URLConnection connection = url.openConnection(); if (connection instanceof JarURLConnection) { connection.setUseCaches(false); return connection; ... |