List of utility methods to do HttpURLConnection Create
HttpURLConnection | createHttpURLConnection(String urlString, int timeout) Create an HTTP connection (GET). URL url = new URL(urlString); URLConnection connetion = url.openConnection(); HttpURLConnection httpConnection = null; if (connetion instanceof HttpURLConnection) { httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setInstanceFollowRedirects(true); httpConnection.setRequestMethod("GET"); httpConnection.setConnectTimeout(timeout); ... |
HttpURLConnection | createHttpURLGetConnection(String url, int timeout) Create an HTTP GET connection with the specified URL HttpURLConnection connection = null; URL serverAddress = null; serverAddress = new URL(url); connection = (HttpURLConnection) serverAddress.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setReadTimeout(timeout); connection.connect(); ... |
HttpURLConnection | getHttpConnection(Proxy prx, URL u, int millis) get Http Connection HttpURLConnection h = null;
h = (prx != null) ? (HttpURLConnection) u.openConnection(prx) : (HttpURLConnection) u.openConnection();
h.setDoOutput(true);
h.setUseCaches(false);
h.setDoInput(true);
h.setAllowUserInteraction(false);
h.setRequestProperty("Accept-Charset", C_ENC);
h.setConnectTimeout(millis);
...
|
HttpURLConnection | getHttpConnection(String urlStr, Proxy proxy) get Http Connection URL url = new URL(urlStr); System.out.println(urlStr + ",proxy:" + proxy); HttpURLConnection conn = null; if (proxy != null) { conn = (HttpURLConnection) url.openConnection(proxy); } else { conn = (HttpURLConnection) url.openConnection(); return conn; |
HttpURLConnection | getHttpConnection(String urlStr, String charSet, Map get Http Connection URL url = new URL(urlStr); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); for (Iterator iterator = props.keySet().iterator(); iterator.hasNext();) { String k = (String) iterator.next(); connection.addRequestProperty(k, props.get(k)); connection.setRequestMethod("GET"); return connection; ... |
URLConnection | getHTTPConnection(String urlString) get HTTP Connection final URL url = new URL(urlString); return url.openConnection(); |
HttpURLConnection | getHttpConnection(URL url) get Http Connection return (HttpURLConnection) url.openConnection();
|
HttpURLConnection | getHttpConnection(URL url, int expectedResponseCode, int connectionTimeout) This method creates a connection to a webpage and then reutrns the connection int count = 0; HttpURLConnection con = null; do { try { Thread.sleep(1000); } catch (InterruptedException e) { con = getHttpConnection(url); ... |
HttpURLConnection | getHttpURLConnection(@Nonnull String urlStr) get Http URL Connection if (!urlStr.startsWith("http://") && !urlStr.startsWith("https://")) { throw new IllegalArgumentException("Unexpected url: " + urlStr); URL url = new URL(urlStr); URLConnection conn = url.openConnection(); return (HttpURLConnection) conn; |
HttpURLConnection | getHttpURLConnection(String postUrl) get Http URL Connection URL url = new URL(postUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestProperty("Content-Type", "application/json"); ... |