C # Programming Summary (12) breakpoint continued transmission

Source: Internet
Author: User

We often use download tools, such as bit elf, Thunderbolt, FlashGet, these software support the continuation of the breakpoint.

The continuation of a breakpoint, when a download task is paused, can continue without having to be downloaded again, that is, the starting location of the server to be notified when downloading. If multithreading is allowed for fragmented downloads, you must provide a start-stop position. In the final analysis, you can choose to download a fragment, the entire file byte stream, you can intercept the flow of fragments, but also to achieve the accumulation of streams, the final completion of the file download.

First, the principle

New in http/1.1 a header attribute: Range, is now many so-called multi-threaded download tools (such as FlashGet, Thunderbolt, etc.) to achieve the core of multi-threaded download. The old version of the HTTP protocol is not supported, so some older servers do not support breakpoint continuation.

Range (Request parameters)

For the request header, specify the position of the first byte and the position of the last byte, in general format:

Range: (Unit=first byte pos)-[last byte POS]

For example: range:100-199, take the bytes between 100 and 199 of the file stream.

Range:100, take the position of all bytes after 100. If the range is positive, the server should begin sending data from the specified range parameter to the end of the data in the HTTP entity.

Range:-99, take the first 100 bytes. If the range is negative, the server should begin sending data from the beginning of the data in the HTTP entity to the specified range parameter.

Content-range (response parameters)

For the response header, specifies the insertion position of a portion of the entire entity, and he also indicates the length of the entire entity. When the server returns a partial response to the customer, it must describe the scope of the response coverage and the entire entity length.

General format:

For example: Content-range:bytes 1024000-1126399/7421120

HTTP protocol: http://www.w3.org/Protocols/rfc2616/rfc2616.html

Two, C # implementation

To add a specified range of byte range headers to a request using the AddRange method in C #

System.Net.HttpWebRequest

All the methods:

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.