Let's talk about today's problems. Previously did an upgrade when the progress bar display effect, do not know what is going on today can not be used (the code is not modified), to see the reason is because Getcontentlength () returned 1 caused, why return 1???? Ghost know, look at the server response header file properties, really do not have this property ... So return to-1 .....
Workaround:
Knowing the reason, the solution is very simple, there are two main methods.
One is server-side resolution, which is mainly to add the method.
The second is to call the. Setrequestproperty ("Accept-encoding", "identity") before calling the function, and the function can be obtained by ...
The problem is explained as follows:
By default,HttpURLConnection uses gzip to get, file getcontentlength () This method, each time read completed can be obtained, the current transfer of how much data, and can not use this method to obtain the need to transmit more A few bytes of content, when read () returns 1, the reading is completed, due to the total length of the compression I can not obtain, then the progress bar can not calculate the value.
To get the length, ask the HTTP request not to gzip compress ...
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The android Getcontentlength () function returned a problem of-1