Export (0) Print
Expand All

HttpWebRequest.AddRange Method (Int32)

Adds a byte range header to a request for a specific range from the beginning or end of the requested data.

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

'Declaration
Public Sub AddRange ( _
	range As Integer _
)
'Usage
Dim instance As HttpWebRequest 
Dim range As Integer

instance.AddRange(range)

Parameters

range
Type: System.Int32

The starting or ending point of the range.

ExceptionCondition
ArgumentException

rangeSpecifier is invalid.

InvalidOperationException

The range header could not be added.

The HttpWebRequest.AddRange method adds a byte range header to the request.

If range is positive, the range parameter specifies the starting point of the range. The server should start sending data from the range parameter specified to the end of the data in the HTTP entity.

If range is negative, the range parameter specifies the ending point of the range. The server should start sending data from the start of the data in the HTTP entity to the range parameter specified.

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.

An example of a Range header in an HTTP protocol request that requests the server send the first 100 bytes (from the start to byte position 99) would be the following:

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

For this example, the range parameter would be -99.

A HTTP server indicates support for Range headers with the Accept-Ranges header. 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

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.

The following code example adds a range header to the request.

            ' A New 'HttpWebRequest' object is created. 
            Dim myHttpWebRequest1 As HttpWebRequest = WebRequest.Create("http://www.contoso.com")
            myHttpWebRequest1.AddRange(1000)
            Console.WriteLine("Call AddRange(1000)")
			      Console.Write("Resulting Headers: ")
			      Console.WriteLine(myHttpWebRequest1.Headers.ToString())

            Dim myHttpWebRequest2 As HttpWebRequest = WebRequest.Create("http://www.contoso.com")
            myHttpWebRequest2.AddRange(-1000)
            Console.WriteLine("Call AddRange(-1000)")
			      Console.Write("Resulting Headers: ")
			      Console.WriteLine(myHttpWebRequest2.Headers.ToString())
            // Create a New 'HttpWebRequest' object.
            HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)
                (WebRequest.Create("http://www.contoso.com"));
            myHttpWebRequest1.AddRange(1000);
			      Console.WriteLine("Call AddRange(1000)");
			      Console.Write("Resulting Headers: ");
			      Console.WriteLine(myHttpWebRequest1.get_Headers());


            // Create a New 'HttpWebRequest' object.
            HttpWebRequest myHttpWebRequest2 = (HttpWebRequest)
                (WebRequest.Create("http://www.contoso.com"));
            myHttpWebRequest2.AddRange(-1000);
			      Console.WriteLine("Call AddRange(-1000)");
			      Console.Write("Resulting Headers: ");
			      Console.WriteLine(myHttpWebRequest2.get_Headers());

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft