如何标记下载失败?

时间:2017-12-04 11:50:07

标签: java google-chrome download httprequest resume-download

当我尝试下载一个大约900 MB的文件并暂停下载并在一段时间后(比如几小时)重试时。 Chrome而不是恢复下载只是将文件标记为已完成。

 public HttpURLConnection getConnection(String url, METHOD method)
            throws IOException, SocketException {
        URL server = new URL(url);
        HttpURLConnection httpsconnection = (HttpURLConnection) server.openConnection();
        if (method == METHOD.POST) {
            httpsconnection.setRequestMethod("POST"); //No i18N
            httpsconnection.setFixedLengthStreamingMode(0);
        } else if (method == METHOD.GET) {
            httpsconnection.setRequestMethod("GET"); //No i18N
        }
        httpsconnection.setDoInput(true);
        httpsconnection.setDoOutput(true);
        httpsconnection.setInstanceFollowRedirects(false);
        httpsconnection.setRequestProperty("connection","keep-alive"); //No i18N
        httpsconnection.setRequestProperty("content-length","0"); //No i18N
        httpsconnection.setConnectTimeout(4000);
        httpsconnection.setReadTimeout(30000);
        return httpsconnection;
    }

我错过了在标题值中设置的内容。当我尝试从其他网站下载文件时,他们只是说"网络 - 断开连接"并暂停下载,可以在一段时间后恢复。

很好奇这个暂停和恢复如何与chrome配合使用。我的浏览器客户端(如Chrome,Firefox)如何了解网络中断。有人可以启发我吗?

0 个答案:

没有答案