更新时间:2023-01-15 17:57:32
要恢复下载,您不仅需要发送 Range
请求头,还有 If-Range
请求标头,其中应包含唯一文件标识符或文件修改时间戳.
To resume a download, you need to send not only the Range
request header, but also the If-Range
request header which should contain either the unique file identifier or the file modification timestamp.
如果服务器返回 ETag
初始下载的响应头,那么您应该在后续恢复请求的 If-Range
头中使用它.或者如果它返回 Last-Modified
响应头,那么你应该在 If-Range
请求头中使用它.
If the server returns an ETag
response header on the initial download, then you should use it in the If-Range
header of the subsequent resume requests. Or if it returns a Last-Modified
response header, then you should use it in the If-Range
request header instead.
查看您的日志,服务器发送了一个 Last-Modified
响应标头.因此,您应该在恢复请求的 If-Range
标头中将其发送回.
Looking at your logs, the server has sent a Last-Modified
response header. So you should send it back along in an If-Range
header of the resume request.
// Initial download.
String lastModified = connection.getHeaderField("Last-Modified");
// ...
// Resume download.
connection.setRequestProperty("If-Range", lastModified);
服务器将使用此信息来验证您请求的文件是否完全相同.
The server will use this information to verify if you're requesting exactly the same file.