您的位置:首页 > 理论基础 > 计算机网络

Http 416错误解决方案

2015-01-07 15:06 148 查看
今天写多线程下载时老报Http416的错误,正常的话应该返回code
206,但是这次却不正常,后来研究了一下,发现如下问题:

以下是错误log:

Server returned HTTP response code: 416 for URL: http://localhost:8080/QQ.exe
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)

at
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
Source)

at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
Source)

at
java.lang.reflect.Constructor.newInstance(Unknown Source)

at
sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown
Source)

at
sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown
Source)

at
java.security.AccessController.doPrivileged(Native Method)

at
sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown
Source)

at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
Source)

at
com.lyc.download.Demo$DownloadThread.run(Demo.java:97)

HTTP response code:
416是由于读取文件时设置的Range有误造成的,具体的说就是下面这行代码有误:

connection.setRequestProperty("Range",
"bytes=:"+startIndex+"-"+endIndex);

中间的冒号:就是罪魁祸首,敲代码的时候不小心多敲了个冒号造成的;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐