搜索引擎如何变别网页是否有改动

HTTP协议有一个称为HEAD的特殊请求.使搜索引擎检查页面更加容易.HEAD请求只返回页面的头部信息.而不是页面内容.

Last-Modified的值就指出了.页面内容最后一次发生变化的时间.

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class HTTPHeadRequestTest {

	public static void main(String[] args) throws Exception {

		URL url = new URL("http://www.javaeye.com/");
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();

		conn.setRequestMethod("HEAD");

		Map<String, List<String>> headerMap = conn.getHeaderFields();
		Iterator<String> iterator = headerMap.keySet().iterator();

		while (iterator.hasNext()) {
			String key = iterator.next();
			List<String> values = headerMap.get(key);
			System.out.println(key + ":" + values.toString());
		}
	}
}



你可能感兴趣的:(exception,String,搜索引擎,url,iterator,Class)