|
|
URL url=new URL("http://www.javathinker.net");
HttpURLConnection.setFollowRedirects(true); //允许重定向
URLConnection connection=url.openConnection();
connection.setConnectTimeout(60000); //超时时间为60秒
connection.setReadTimeout(60000);
Map<String,List<String>> headers=connection.getHeaderFields();
Set<String> keySet=headers.keySet();
for(String key:keySet){ //遍历头部的所有信息
//同一项会有多一个值,此处仅显示第一个值
System.out.println(key+":"+headers.get(key).get(0)); //
}
String location=connection.getHeaderField("Location"); //读取特定的项 |
程序猿的技术大观园:www.javathinker.net
|
|