public static void main(String[] args) throws Exception {
URL url = new URL();
HttpURLConnection conn = (HttpURLConnection) urlopenConnection();
// connsetDoOutput(true);
connsetRequestMethod(HEAD);
Map<String List<String>> headerMap = conngetHeaderFields();
Iterator<String> iterator = headerMapkeySet(erator();
while (iteratorhasNext()) {
String key = iteratornext();
List<String> values = headerMapget(key);
Systemoutprintln(key + : + valuestoString());
}
}
返回结果
Java代码
null:[HTTP/ OK]
ETag:[]
Date:[Thu Feb :: GMT]
ContentLength:[]
LastModified:[Thu Jan :: GMT]
ContentType:[text/html]
AcceptRanges:[bytes]
Server:[lig]