Here you can find the source of printHeaderFields(final URL url)
public static void printHeaderFields(final URL url)
//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 void printHeaderFields(final URL url) { URLConnection conn = null; try {//from ww w . j a v a 2 s. c om // Create a URLConnection object for a URL conn = openConnection(url); for (final String name : conn.getHeaderFields().keySet()) { System.out.println(name + "\t" + conn.getHeaderField(name)); } } catch (Exception e) { e.printStackTrace(); } 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; } public static String getHeaderField(final URL url, final String name) { URLConnection conn = null; try { // 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(); } } } }