Here you can find the source of getResponseHeader(HttpURLConnection conn)
public static String getResponseHeader(HttpURLConnection conn)
//package com.java2s; //License from project: Apache License import java.net.HttpURLConnection; public class Main { public static String getResponseHeader(HttpURLConnection conn) { String headerField = conn.getHeaderField(null); if (headerField == null) { return null; }/* www . j av a2 s . c o m*/ StringBuffer sb = new StringBuffer(); sb.append(headerField).append("\r\n"); String key; for (int i = 1; (key = conn.getHeaderFieldKey(i)) != null; i++) { if (!key.equals("Transfer-Encoding")) sb.append(key).append(": ").append(conn.getHeaderField(i)).append("\r\n"); } return sb.toString(); } public static String getResponseHeader(HttpURLConnection conn, String modifiedKey, String newValue) { StringBuffer sb = new StringBuffer(); sb.append(conn.getHeaderField(null)).append("\r\n"); String key; String value; for (int i = 1; (key = conn.getHeaderFieldKey(i)) != null; i++) { if (key.equals("Transfer-Encoding")) continue; if (key.equals(modifiedKey)) value = newValue; else value = conn.getHeaderField(i); sb.append(key).append(": ").append(value).append("\r\n"); } return sb.toString(); } }