Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在http请求中指定范围?_Java_Http_Outputstream - Fatal编程技术网

Java 如何在http请求中指定范围?

Java 如何在http请求中指定范围?,java,http,outputstream,Java,Http,Outputstream,我发出如下http请求: Outputstream os; os.write(("GET /Lifted-"+file+"p.dat HTTP/1.0\r\n\r\n").getBytes()); 但在请求中,我想指定在该文件中,我希望以某个偏移量(例如2000)开始,以偏移量10000结束。我怎样才能到达那个范围? 谢谢。在刷新流之前,您可以在outputstream中添加范围标头。尝试以下方法: os.write(("GET /Lifted-"+file+"p.dat HTTP/1.0\r

我发出如下http请求:

Outputstream os;
os.write(("GET /Lifted-"+file+"p.dat HTTP/1.0\r\n\r\n").getBytes());
但在请求中,我想指定在该文件中,我希望以某个偏移量(例如2000)开始,以偏移量10000结束。我怎样才能到达那个范围?
谢谢。

在刷新流之前,您可以在outputstream中添加范围标头。尝试以下方法:

os.write(("GET /Lifted-"+file+"p.dat HTTP/1.0\r\n").getBytes());
os.write("Range : bytes=2000-10000\r\n".getBytes());
os.write("\r\n".getBytes());
os.flush();
也许这能帮你


注意:检查ietf文档中的范围标题:

什么的范围?
文件的内容是什么?为什么要使用HTTP的低级接口?整数也在括号内??范围整数不在括号内请告诉我是否需要任何其他说明。
Accept Ranges
标头仅由服务器发送,而不是由客户端发送。看见