HttpUrlConnect获取响应头
import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Map; public class GetHeader { public static void main(String[] args) { URLConnection conn; try { URL obj = new URL("http://192.168.1.105:8010/eoffice10/server/public/api/"); conn = obj.openConnection(); Map<String, List<String>> map = conn.getHeaderFields(); // Map<String, List<String>> map2 = conn.getRequestProperties(); System.out.println("显示响应Header信息...\n"); for (Map.Entry<String, List<String>> entry : map.entrySet()) { System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue()); } System.out.println("Authorization---->"+map.get("Authorization")); System.out.println("\n使用key获得响应Header信息 \n"); List<String> server = map.get("Server"); if (server == null) { System.out.println("Key 'Server' is not found!"); } else { for (String values : server) { System.out.println(values); } } } catch (IOException e) { e.printStackTrace(); } } }