List of utility methods to do HTTP Header
void | fillHeaders(HttpURLConnection urlConnection, Map fill Headers if (headers == null) return; for (Entry<String, String> entry : headers.entrySet()) { urlConnection.setRequestProperty(entry.getKey(), entry.getValue()); |
InputStream | GET_Stream(String url, HashMap GE Stream HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod(GET); for (Map.Entry<String, String> entry : headers.entrySet()) { con.setRequestProperty(entry.getKey(), entry.getValue()); return con.getInputStream(); |
HttpURLConnection | getConnection(URL url, String method, Map get Connection HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod(method); conn.setRequestProperty("Content-Type", "application/json"); if (header != null && header.size() > 0) for (Entry<String, String> entry : header.entrySet()) { ... |
String | getFromUrl(Map get From Url String encode = "UTF-8"; String result = ""; try { HttpURLConnection urlCon; if (proxy == null) { urlCon = (HttpURLConnection) loc.openConnection(); } else { urlCon = (HttpURLConnection) loc.openConnection(proxy); ... |
String | getHeaderField(final URL url, final String name) get Header Field URLConnection conn = null; try { conn = openConnection(url); return conn.getHeaderField(name); } catch (IOException e) { e.printStackTrace(); return null; } finally { ... |
Map | getHttpResponseHeader(HttpURLConnection http) get Http Response Header Map<String, String> header = new LinkedHashMap<String, String>(); for (int i = 0;; i++) { String mine = http.getHeaderField(i); if (mine == null) break; header.put(http.getHeaderFieldKey(i), mine); return header; ... |
int | getIntFromHeader(HttpURLConnection connection, String headerName) get Int From Header return connection.getHeaderFieldInt(headerName, -1);
|
long | getLastModifiedHeader(URL url) get Last Modified Header URLConnection conn = url.openConnection(); try { if (conn instanceof HttpURLConnection) { ((HttpURLConnection) conn).setRequestMethod("HEAD"); return conn.getLastModified(); } finally { if (conn instanceof HttpURLConnection) { ... |
String | getServerHeader(URL httpURL) Get the content of the 'Server' header. String ret; try { HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection(); connection.setRequestMethod("HEAD"); connection.setConnectTimeout(3000); connection.setReadTimeout(1000); connection.connect(); connection.getResponseCode(); ... |
Map | getURLHeaders(String u) get URL Headers URL url = new URL(u); HttpURLConnection.setFollowRedirects(true); HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setConnectTimeout(5000); uc.setReadTimeout(5000); uc.setRequestMethod("HEAD"); uc.setRequestProperty("Connection", "Close"); uc.connect(); ... |