List of utility methods to do HttpURLConnection Create
HttpURLConnection | getHttpURLConnection(String strUrl) get Http URL Connection URL url = new URL(strUrl); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); return httpURLConnection; |
HttpURLConnection | getHttpURLConnection(String uri, String soapAction, boolean soap12) Sets up a connection to an HTTP endpoint URL endPointURL = new URL(uri); HttpURLConnection connection = (HttpURLConnection) endPointURL.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.addRequestProperty("SOAPAction", soapAction); if (soap12) { connection.setRequestProperty("Content-Type", "application/soap+xml"); ... |
URLConnection | getHttpUrlConnection(String url) get Http Url Connection try { URLConnection uc = new URL(url).openConnection(); uc.connect(); return uc; } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); |
HttpURLConnection | getHttpURLConnection(String urlAsString) Returns an 'optimized'/fast HttpUrlConnection URL url = new URL(urlAsString); HttpURLConnection hConn = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY); hConn.setInstanceFollowRedirects(false); hConn.setRequestMethod("HEAD"); return hConn; |
HttpURLConnection | getHttpUrlConnection(String urlStr) Return URL object by given URL string, proxy is considered HttpURLConnection conn = null; try { URL url = new URL(urlStr); if (proxy != null) { conn = (HttpURLConnection) url.openConnection(proxy); } else { conn = (HttpURLConnection) url.openConnection(); } catch (Exception e) { return null; return conn; |
HttpURLConnection | getHttpUrlConnection(URL url) Returns a HttpUrlConnection for a URL pointing to an HTTP resource. URLConnection connection = url.openConnection(); if (connection instanceof HttpURLConnection) { return (HttpURLConnection) connection; } else { throw new IllegalArgumentException("Url is not targeted at an HTTP resource" + url); |
HttpURLConnection | getHttpURLConnection(URL url) get Http URL Connection if (proxy != null) { return (HttpURLConnection) url.openConnection(proxy); } else { return (HttpURLConnection) url.openConnection(); |