Java Utililty Methods HTTP Header

List of utility methods to do HTTP Header

Description

The list of methods to do HTTP Header are organized into topic(s).

Method

voidfillHeaders(HttpURLConnection urlConnection, Map headers)
fill Headers
if (headers == null)
    return;
for (Entry<String, String> entry : headers.entrySet()) {
    urlConnection.setRequestProperty(entry.getKey(), entry.getValue());
InputStreamGET_Stream(String url, HashMap headers)
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();
HttpURLConnectiongetConnection(URL url, String method, Map header, String ctype)
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()) {
...
StringgetFromUrl(Map headerMap, URL loc, Proxy proxy)
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);
...
StringgetHeaderField(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 {
...
MapgetHttpResponseHeader(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;
...
intgetIntFromHeader(HttpURLConnection connection, String headerName)
get Int From Header
return connection.getHeaderFieldInt(headerName, -1);
longgetLastModifiedHeader(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) {
...
StringgetServerHeader(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();
...