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: