我想知道是否可以通过http请求获取网页的大小。
我用它来获得预言机页面长度:
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
List<String> get = yc.getHeaderFields().get("content-Length");
但是当我将其用于 Google 页面时,标题中没有内容长度。
最佳答案
您必须使用正确的大写或小写。字段名称是 Content-Length
而不是 content-Length
。您还可以使用 URLConnection 对象
的 getContentLength()
方法。任何需要发送 HTTP 正文的应用程序都应该使用此字段,Google 就是这样做的。
请注意,Google 使用安全连接。
关于Java HTTP 请求 : get content size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28345525/