"IOS" resumable doanloads (breakpoint download)

Source: Internet
Author: User

Here we only discuss the General app under the iOS platform, we can write our own code to implement the resume downloads, explained below.

Resume an HTTP download is not difficult, but you must understand some of the key HTTP concepts:

    • Entity tag: This is a unique identifier provided by a server that represents a specific version of a specific resource, and if someone changes the resource on the server, the entity tag will change.
    • Range Header: With this, you can request a resource to specify a range of bytes.
    • If-range Header: This indicates that you want a resource within a specified range of bytes if the entity tag has not changed.

Note: If the server does not provide an entity tag, it can be replaced with the current time.

The basic strategies of Resuming download are as follows:

    1. If the download has been initialized, the resource-related entity tag is pure;
    2. Remember how much data is valid when the data is stored on disk;
    3. To resume the download, get the entity tag and the amount of data that has been stored, and give these values to the range and If-range header request;
    4. Execute request. Success (you receive the remainder of this resource), or fail (to prevent you from starting from scratch requesting resources).

An HTTP Resume request:

Get/download.info.apple.com/[...] /MACOSXUPDCOMBO10.6.8.DMG http/1.1host:supportdownload.apple.comuser-agent:safari/7534.52.7 [...] Accept: */*if-range: "968f3f3e86e0339ce722170ae656bc73:1319461845" Range:bytes=4041400-accept-language: En-auaccept-encoding:gzip, deflate[...] Connection:keep-alive

The range header tells the server that you want to get the data starting at offset 4041400. If-range head tells the server that I just want to get the data after the server's entity tag gives me the data without changing the case.

An HTTP Resume response:

http/1.1 206 Partial contentserver:apacheaccept-ranges:bytescontent-type:application/octet-streamlast-modified: Mon, Oct 13:04:42 gmtetag: "968f3f3e86e0339ce722170ae656bc73:1319461845" Date:mon, Jan 16:13:25 gmtcontent -range:bytes 4041400-1087036999/1087037000content-length:1082995600connection:keep-alive

HTTP status Code 206 indicates that response only includes a subset (part) of the requested resource, and the Content-range header accurately represents the range of returned resources (bytes from 4041400 to 1087036999) and the total length of the resource (1087037000). The Content-length header tells you the number of bytes returned by the server in this response.

"IOS" resumable doanloads (breakpoint download)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.