niumoo / down-bit

一个 Java 实现的,多线程,断点续传下载器

Home Page:https://www.wdbyte.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getUrlConnection获取inputStream报416错误

wu964362048 opened this issue · comments

public static HttpURLConnection getHttpUrlConnection(String url, long start, Long end) throws IOException {
    HttpURLConnection httpUrlConnection = getHttpUrlConnection(url);
    if (end != null) {
        httpUrlConnection.setRequestProperty("RANGE", "bytes=" + start + "-" + end);
    } else {
        httpUrlConnection.setRequestProperty("RANGE", "bytes=" + start + "-");
    }
    return httpUrlConnection;
}

该方法中的有end范围增加 ”/*“之后会发生错误,在获取inputStream的时候会报416错误,在qq/微信的下载链接中均会报错

确实有这个问题,现在版本已经去掉末尾的 /* 了,当初加这个 /* 也是阅读了 HTTP 请求头的规范写进去的,后来发现某些网站不支持,像你说的会报错,还有些会让 Range 参数失效,原因还不清楚。