Java HTTP Header getHeaderField(final URL url, final String name)

Here you can find the source of getHeaderField(final URL url, final String name)

Description

get Header Field

License

Open Source License

Declaration

public static String getHeaderField(final URL url, final String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.net.URLConnection;
import java.net.URL;
import java.net.HttpURLConnection;

public class Main {
    public static String getHeaderField(final URL url, final String name) {
        URLConnection conn = null;
        try {//from  ww w  .j  av a 2 s. com
            // Create a URLConnection object for a URL
            conn = openConnection(url);
            return conn.getHeaderField(name);

        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } finally {
            if (conn != null && conn instanceof HttpURLConnection) {
                ((HttpURLConnection) conn).disconnect();
            }
        }
    }

    private static URLConnection openConnection(final URL url) throws IOException {
        URLConnection conn = url.openConnection();
        conn.setReadTimeout(3000);
        conn.setDefaultUseCaches(false);
        conn.setUseCaches(false);
        return conn;
    }
}

Related

  1. dumpHttpHeaders(HttpURLConnection conn, java.io.PrintStream out)
  2. fillHeaders(HttpURLConnection urlConnection, Map headers)
  3. GET_Stream(String url, HashMap headers)
  4. getConnection(URL url, String method, Map header, String ctype)
  5. getFromUrl(Map headerMap, URL loc, Proxy proxy)
  6. getHttpResponseHeader(HttpURLConnection http)
  7. getIntFromHeader(HttpURLConnection connection, String headerName)
  8. getLastModifiedHeader(URL url)
  9. getServerHeader(URL httpURL)