为什么Range标头会返回整个文件?

时间:2017-12-18 20:54:02

标签: java http-headers range httpurlconnection

我试图使用以下代码从字节0到字节0获取文件的一部分。当我在本地服务器(wampserver)内的文件上测试此代码并打印此部分的大小时,它将返回我的大小1.但是当我在互联网上的某些文件上测试此代码时,我打印的大小这一部分,它将返回整个文件的大小!

为什么会这样?这是什么原因?

我的代码是这样的:

URL url = new URL("my link");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept-Encoding", "identity");
connection.setRequestProperty("Range", "bytes=" + 0 + "-" + 0);
connection.connect();
Log.i("Test" , "size: " + connection.getContentLength());

0 个答案:

没有答案