GetContentLength () returns -1 only in WiFi?

I want to know the file length, so I tried getContentLength(). It works fine with network connectivity (edge ​​/ 3g), but returns -1 with WiFi?
What for? Wi-fi is good and the file was found, it can be downloaded, but the return is getContentLength()always "-1". I do not understand. file- google docs file.
Is there any other way to get the length?

My code is:

URL url = new URL(file);

URLConnection conexion = url.openConnection();

conexion.connect();

int poids = conexion.getContentLength();
+3
source share
2 answers

, . , ( ). "" , - , .

... , .

+1

, HTTP-.

getContentLength() "" , . HTTP, , , , -1.

Transfer-Encoding; chunked- chunked. HTTP- Content-Length, ; Content-Length , Content-Length.

, - , . , . - , . HTTP-, .

+1

Source: https://habr.com/ru/post/1758276/


All Articles