Export (0) Print
Expand All

HttpWebRequest.AddRange Method (String, Int64, Int64)

Adds a range header to a request for a specified range.

Namespace:  System.Net
Assembly:  System (in System.dll)

member AddRange : 
        rangeSpecifier:string * 
        from:int64 * 
        to:int64 -> unit

Parameters

rangeSpecifier
Type: System.String

The description of the range.

from
Type: System.Int64

The position at which to start sending data.

to
Type: System.Int64

The position at which to stop sending data.

ExceptionCondition
ArgumentNullException

rangeSpecifier is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

from is greater than to

-or-

from or to is less than 0.

ArgumentException

rangeSpecifier is invalid.

InvalidOperationException

The range header could not be added.

The HttpWebRequest.AddRange method adds a Range header to the request.

Since all HTTP entities are represented in HTTP messages as sequences of bytes, the concept of a byte range is meaningful for any HTTP entity. However, not all clients and servers need to support byte-range operations.

The Range header on a request allows a client to request that it only wants to receive some part of the specified range of bytes in an HTTP entity. Servers are not required to support Range header requests.

The rangeSpecifier parameter would normally be specified as a "bytes", since this is the only range specifier recognized by most HTTP servers. Setting the rangeSpecifier parameter to some other string allows support for custom range specifiers other than bytes (the byte-range specifier defined in RFC 2616 by the IETF).

An example of a Range header in an HTTP protocol request that requests the first 100 bytes would be would be the following:

Range: bytes=0-99\r\n\r\n

For this example, the rangeSpecifier parameter would be specified as a "bytes", the from parameter would be 0, and the to parameter would be 99.

A HTTP server indicates support for Range headers with the Accept-Ranges header in the response. An example of the Accept-Ranges header from a server that supports byte-ranges would be as follows:

Accept-Ranges: bytes\r\n\r\n

The string specified in the Accept-Ranges header is the range-specifier that would be by specified in the rangeSpecifier parameter for this method.

If an Accept-Ranges header is not received in the header of the response from the server, then the server does not support Range headers. An example of the Accept-Ranges header from a server that does not support ranges, but recognizes the Accept-Ranges header, would be as follows:

Accept-Ranges: none\r\n\r\n

When receiving the response from a range request, only the HTTP headers associated with the entire request are parsed and made available via properties on the HttpWebResponse class. Headers associated with each range are returned in the response.

.NET Framework

Supported in: 4.5, 4

.NET Framework Client Profile

Supported in: 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft