try{
URL url = new URL("http://www.runoob.com");
URLConnection conn = url.openConnection();
Map headers = conn.getHeaderFields();
Set<String> keys = headers.keySet();
for( String key : keys ){
String val = conn.getHeaderField(key);
System.out.println(key+" "+val);
}
//System.out.println( conn.getLastModified() );
}catch(IOException e){
}finally {
}
运行结果:
null HTTP/1.1 301 Moved Permanently
Server Tengine
Timing-Allow-Origin *
Connection keep-alive
Content-Length 278
EagleId 71606d1d15994460009901638e
Date Mon, 07 Sep 2020 02:33:20 GMT
Via cache9.cn747[,0]
Location https://www.runoob.com/
Content-Type text/html