u010880786
香辣鸡丁煲
采纳率56.5%
2016-04-14 02:59 阅读 1.9k

为什么设置了请求头为range格式,服务器返回码却是200而不是206呢?

HTTP1.1 中的状态码与状态描述中有写道
206 Partial Content 客户发送了一个带有Range头的GET请求,服务器完成了它(HTTP 1.1新)。
然后我的客户端代码:

 HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(5000);
connection.setRequestProperty("Range", "bytes-" + startIndex                        + "-" + endIndex);
Log.i("hhh", connection.getResponseCode()+"");//返回值为200

服务器部分代码:

 response.setContentType("Application/Octet-stream;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="
+ fName+"");
FileInputStream is = new FileInputStream(f);
OutputStream os = response.getOutputStream();
int len = 0;
byte[] bs = new byte[2048];
while((len=is.read(bs))>0)
{
os.write(bs, 0, len);
}   
response.setCharacterEncoding("UTF-8");
is.close();
os.flush();
os.close();

求解答,谢谢,谢谢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

相关推荐