使用http Header我试图通过java的http连接从头部获取网站调用的长度..但问题是我的结果与不同的httpheader在线工具中找到的真实结果不兼容
这是我的代码:
public static URLConnection getConnection(String url) throws IOException {
URL obj = new URL(url);
URLConnection conn = obj.openConnection();
// conn.setRequestProperty("User-Agent",
// "Mozilla/5.0 (Linux ; Android 6.0.1 ; Nexus 5X Build/MMB29P) AppleWebKit/537.36" +
// " (KHTML, par exemple Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible ; Googlebot/2.1 ; +http://www.google.com/bot.html)");
return conn;
}
我从标题中调用contentLegth字段,但我得到的结果是1037Bytes,真值必须是:128241 Kb
public static Boolean PageWeightFromServer(URLConnection c) throws IOException {
int length = c.getContentLength(); // The weight of the page received in the responseHeader
System.err.println(length +"Bytes");
return (length>500);
}