简体   繁体   English

为什么Content-Length返回-1?

[英]Why Content-Length returning -1?

HttpURLConnection conn = (HttpURLConnection) new URL("http://cuonline.ac.in/ranking/cap_admitted.php?clg=231").openConnection();
        System.out.println(conn.getContentLength());

Why it's returning the content length as -1 ? 为什么返回内容长度为-1 Is am doing anything wrong? 做错什么了吗?

That header might not be set for that page by the server, might not have finished loading when that statement executes and/or you might have connectivity issues. 服务器可能未为该页面设置该标头,该语句执行时可能尚未完成加载,和/或您可能遇到连接问题。

See http://developer.android.com/reference/java/net/URLConnection.html#getContentLength%28%29 参见http://developer.android.com/reference/java/net/URLConnection.html#getContentLength%28%29

As for your specific URL it looks like it's not set 至于您的特定网址,似乎未设置

SERVER RESPONSE: HTTP/1.1 200 OK
Date:
    Sun, 02 Aug 2015 16:02:49 GMT
Server:
    Apache/2.2.14 (Ubuntu)
X-Powered-By:
    PHP/5.3.2-1ubuntu4.29
Vary:
    Accept-Encoding
Connection:
    close
Content-Type:
    text/html

http://tools.seobook.com/server-header-checker/?page=single&url=http%3A%2F%2Fcuonline.ac.in%2Franking%2Fcap_admitted.php%3Fclg%3D231&useragent=1&typeProtocol=11 http://tools.seobook.com/server-header-checker/?page=single&url=http%3A%2F%2Fcuonline.ac.in%2Franking%2Fcap_admitted.php%3Fclg%3D231&useragent=1&typeProtocol=11

You may have to read the content conn.getInputStream() and count that instead. 您可能必须阅读内容conn.getInputStream()并对其进行计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM