This documentation is archived and is not being maintained.

HttpWebRequest.AddRange Method (Int32, Int32)

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

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

Public Sub AddRange ( _
	from As Integer, _
	to As Integer _
Dim instance As HttpWebRequest
Dim from As Integer
Dim to As Integer

instance.AddRange(from, to)
public void AddRange (
	int from, 
	int to
public function AddRange (
	from : int, 
	to : int



The position at which to start sending data.


The position at which to stop sending data.

Exception typeCondition


rangeSpecifier is invalid.


from is greater than to


from or to is less than 0.


The range header could not be added.

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

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

' A New 'HttpWebRequest' objetc is created.
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create("")
myHttpWebRequest.AddRange(50, 150)
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Displaying the contents of the page to the console
Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuffer(256) As [Char]
Dim count As Integer = streamRead.Read(readBuffer, 0, 256)
Console.WriteLine(ControlChars.Cr + "The HTML contents of the page from 50th to 150 charaters are :" + ControlChars.Cr + "  ")
While count > 0
    Dim outputData As New [String](readBuffer, 0, count)
    count = streamRead.Read(readBuffer, 0, 256)
End While
' Release the response object resources.

// Create a New 'HttpWebRequest' object.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
myHttpWebRequest.AddRange(50, 150);
// Assign the response object of 'HttpWebRequest' to a 
// 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
// Display the contents of the page to the console.
Stream streamResponse = myHttpWebResponse.GetResponseStream();
StreamReader streamRead =  new StreamReader(streamResponse);
char readBuffer[] = new char[256];
int count = streamRead.Read(readBuffer, 0, 256);
Console.WriteLine("\nThe HTML contents of the page from 50th" 
    + " to 150 charaters are :\n  ");
while(count > 0) {
    String outputData =  new String(readBuffer, 0, count);
    count = streamRead.Read(readBuffer, 0, 256);
// Release the response object resources.

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

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0