Share via


AddRange Method (String, Int32)

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

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

Syntax

'Declaration
Public Sub AddRange ( _
    rangeSpecifier As String, _
    range As Integer _
)
public void AddRange(
    string rangeSpecifier,
    int range
)
public:
void AddRange(
    String^ rangeSpecifier, 
    int range
)
member AddRange : 
        rangeSpecifier:string * 
        range:int -> unit 
public function AddRange(
    rangeSpecifier : String, 
    range : int
)

Parameters

Remarks

The HttpWebRequest..::..AddRange method adds a 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.

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=-99\r\n\r\n

For this example, the rangeSpecifier parameter would be specified as "bytes" and the range 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

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 Security

See Also

Reference

HttpWebRequest Class

AddRange Overload

System.Net Namespace