http://www.mkyong.com/java/how-to-get-http-response-header-in-java/headerFields 应该是 HTTP 的一组 key value pairs, 比如 "Server" 什么的。
====================================================
URL obj = new URL("
http://mkyong.com");
URLConnection conn = obj.openConnection();
//get all headers
Map<String, List<String>> map = conn.getHeaderFields();
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
System.out.println("Key : " + entry.getKey() +
" ,Value : " + entry.getValue());
}
//get header by 'key'
String server = conn.getHeaderField("Server");
====================================================
HttpClient client = HttpClientBuilder.create().build();
HttpGet request = new HttpGet("
http://mkyong.com");
HttpResponse response = client.execute(request);
//get all headers
Header[] headers = response.getAllHeaders();
for (Header header : headers) {
System.out.println("Key : " + header.getName()
+ " ,Value : " + header.getValue());
}
//get header by 'key'
String server = response.getFirstHeader("Server").getValue();本回答被提问者采纳