That's because the content length is not known, as the docs mention.
Tells the length of the content, if known.
Returns:
the number of bytes of the content, or a negative number if unknown. If the content length is known but exceeds Long.MAX_VALUE
, a negative number is returned.
When is the Content-Length header missing?
The HTTP specifications does allow the Content-Length
to be missing if, for example, the Transfer-Encoding
field is set. That is another way to check the length of the message.
How to show the download progress?
You should keep in mind that you cannot always determine the content length beforehand.
One thing you can do, is showing an indeterminate progress bar, like this:

It shows the user the progress, but indicates that the progress value is indeterminate.
How to do so, see this question and answer.