List of utility methods to do HttpURLConnection Open
HttpURLConnection | openConnection(final String urlString) open Connection final URL url = new URL(urlString); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); return connection; |
HttpURLConnection | openConnection(final URL url, final String requestMethod) open Connection final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod(requestMethod); return connection; |
HttpURLConnection | openConnection(String url, String method, String contentType, String ssic) open Connection URL realURL = new URL(url); HttpURLConnection conn = (HttpURLConnection) realURL.openConnection(); conn.setRequestProperty("User-Agent", "IIC2.0/PC 4.0.0000"); conn.setRequestProperty("Cookie", "ssic=" + ssic); conn.setRequestProperty("Host", realURL.getHost()); conn.setRequestProperty("Accept", "*/*"); conn.setRequestProperty("Cache-Control", "no-cache"); if (contentType != null) ... |
HttpURLConnection | openConnection(URL url, Proxy proxy) open Connection HttpURLConnection result = (HttpURLConnection) url.openConnection(proxy);
result.setConnectTimeout(15000);
result.setReadTimeout(15000);
result.setUseCaches(false);
return result;
|
InputStream | openConnectionCheckRedirects(URLConnection c) open Connection Check Redirects boolean redir; int redirects = 0; InputStream in = null; do { if (c instanceof HttpURLConnection) { ((HttpURLConnection) c).setInstanceFollowRedirects(false); in = c.getInputStream(); ... |
HttpURLConnection | getConnection(String url) get Connection try { return (HttpURLConnection) new URL(url.startsWith("http://") ? url : "http://" + url).openConnection(); } catch (Exception e) { return null; |
HttpURLConnection | getConnection(String urlStr, boolean useProxy) get Connection Authenticator authenticator = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return (new PasswordAuthentication("fis\\haint51", "qwer4321!".toCharArray())); }; Authenticator.setDefault(authenticator); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.fis.vn", 8080)); if (!useProxy) { ... |
HttpURLConnection | getConnection(URL url) get Connection HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Accept", "application/zip;text/html"); return conn; |
String | getConnectionCharset(HttpURLConnection connection) Parse the connection content type and return the content charset String contentType = connection.getContentType(); int charsetIndex = contentType.indexOf(CHARSET_KEY); if (charsetIndex != -1) { int charsetEndIndex = contentType.indexOf(";", charsetIndex); if (charsetEndIndex == -1) { return contentType.substring(charsetIndex + CHARSET_KEY.length()); } else { return contentType.substring(charsetIndex + CHARSET_KEY.length(), charsetEndIndex); ... |
BufferedReader | getConnectionStream(HttpURLConnection con) This method is used to get a connection stream from an HTTP connection. InputStream is = con.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); return br; |