Here you can find the source of getHttpHeaders(URLConnection connection)
Parameter | Description |
---|---|
connection | Connection with HTTP headers |
public static Map<String, String> getHttpHeaders(URLConnection connection)
//package com.java2s; //License from project: Open Source License import java.net.URLConnection; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { /**//from w w w . ja va2s .c o m * Extract HTTP headers from a connection. * @param connection Connection with HTTP headers * @return Map of HTTP headers <name, value> */ public static Map<String, String> getHttpHeaders(URLConnection connection) { Map<String, String> mapHeaders = new HashMap<>(); for (Map.Entry<String, List<String>> entries : connection.getHeaderFields().entrySet()) { mapHeaders.put(entries.getKey() == null ? "Status code" : entries.getKey(), String.join(",", entries.getValue())); } return mapHeaders; } }