1

I want to know if it's possible to get the size of a web page with a http request.

I use this to have oracle page length :

URL oracle = new URL("http://www.oracle.com/");
URLConnection yc = oracle.openConnection();
List<String> get = yc.getHeaderFields().get("content-Length");

But when I use this to a google page I do not have content-length in the header.

2
  • 1
    You must use the correct upper or lower cases. The field name is "Content-Length" not "content-Length". You can also use the getContentLength() method of the URLConnection object. This field should be used by any application that need to send a HTTP body, and google does it so. Commented Feb 5, 2015 at 13:47
  • @Jean-BaptisteYunès That should be an answer. Commented Feb 5, 2015 at 13:57

2 Answers 2

1

You must use the correct upper or lower cases. The field name is Content-Length not content-Length. You can also use the getContentLength() method of the URLConnection object. This field should be used by any application that need to send a HTTP body, and google does it so.

Be aware that Google uses secured connections.

Sign up to request clarification or add additional context in comments.

Comments

0

Content-Length is only going to be applicable if the response is not chunked. Generally static content will not be chunked, but in many cases dynamic content will not be chunked.

In the case of www.oracle.com, you will be redirected to www.oracle.com/index.html, which is static content and does provide Content-Length.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.