Java HTTP 请求:获取内容大小
Java HTTP Request : get content size
我想知道是否可以通过http请求获取网页的大小。
我用它来计算 oracle 页面长度:
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
List<String> get = yc.getHeaderFields().get("content-Length");
但是当我将它用于 google 页面时,我在 header.
中没有 content-length
Content-Length 只有在响应不是 chunked 时才适用。
一般静态内容不会分块,但很多情况下动态内容不会分块。
在 www.oracle.com 的情况下,您将被重定向到 www.oracle.com/index.html,这是静态内容并提供 Content-Length。
您必须使用正确的大小写。字段名称是 Content-Length
而不是 content-Length
。您还可以使用 URLConnection object
的 getContentLength()
方法。任何需要发送 HTTP 正文的应用程序都应该使用该字段,google 就是这样做的。
请注意 Google 使用安全连接。
我想知道是否可以通过http请求获取网页的大小。
我用它来计算 oracle 页面长度:
URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
List<String> get = yc.getHeaderFields().get("content-Length");
但是当我将它用于 google 页面时,我在 header.
中没有 content-lengthContent-Length 只有在响应不是 chunked 时才适用。 一般静态内容不会分块,但很多情况下动态内容不会分块。
在 www.oracle.com 的情况下,您将被重定向到 www.oracle.com/index.html,这是静态内容并提供 Content-Length。
您必须使用正确的大小写。字段名称是 Content-Length
而不是 content-Length
。您还可以使用 URLConnection object
的 getContentLength()
方法。任何需要发送 HTTP 正文的应用程序都应该使用该字段,google 就是这样做的。
请注意 Google 使用安全连接。