I am using this question's source code How to asynchronous perform a httprequest and show the progress of downloading the response in order to fetch a webpage's html source and display a progressbar with the downloaded data so far and how much the total size of the page is.
That particular code doesn't actually work on ICS 4.0.3 because clHeaders[0] doesn't point to anything and an exception is raised called ArrayIndexOutOfBounds at index 0 because the Content-Length header is omitted from the server's response. I tried using getContentLength in case that was the problem - it returned a negative value of -1 then I iterated over all the headers and the Content-Length was not there. After removing those bits, the code works fine and a webpage is fetched, written to a file and the size as it is being downloaded is displayed but obviously not the end size till I actually download it all.
I only have three ideas of the cause:
- I am not sending a Content-Length header thus I am not receiving one either - but this sounds wrong. Plus I have no idea if the HttpClient isn't sending one in the background.
- I read here in another question that if the response of the server was streaming or chunked then getContentLength can return -1.
- Gzip? But I have no idea how to disable it or if it was enabled in the first place
If you are thinking it's the server that is broken, I tried many websites including Google and still no Content-Length header whatsoever.