当前位置:   article > 正文

Http 416错误解决方案_错误 416

错误 416
今天写多线程下载时老报Http416的错误,正常的话应该返回code 206,但是这次却不正常,后来研究了一下,发现如下问题:
  以下是错误log:
Server returned HTTP response code: 416 for URL: http://localhost:8080/QQ.exe
      at sun.reflect.NativeConstructorAccesso rImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccesso rImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAcc essorImpl.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);

中间的冒号:就是罪魁祸首,敲代码的时候不小心多敲了个冒号造成的;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/259698
推荐阅读
相关标签
  

闽ICP备14008679号