HttpWebRequest.AddRange 方法

定义

向请求添加范围标头。Adds a range header to the request.

重载

AddRange(Int32)

向请求添加从请求数据的开始处或结束处的特定范围的字节范围标头。Adds a byte range header to a request for a specific range from the beginning or end of the requested data.

AddRange(Int64)

向请求添加从请求数据的开始处或结束处的特定范围的字节范围标头。Adds a byte range header to a request for a specific range from the beginning or end of the requested data.

AddRange(Int32, Int32)

向请求添加指定范围的字节范围标头。Adds a byte range header to the request for a specified range.

AddRange(Int64, Int64)

向请求添加指定范围的字节范围标头。Adds a byte range header to the request for a specified range.

AddRange(String, Int32)

向请求添加从请求数据的开始处或结束处计算的特定范围的 Range 标头。Adds a Range header to a request for a specific range from the beginning or end of the requested data.

AddRange(String, Int64)

向请求添加从请求数据的开始处或结束处计算的特定范围的 Range 标头。Adds a Range header to a request for a specific range from the beginning or end of the requested data.

AddRange(String, Int32, Int32)

向请求添加指定范围的范围标头。Adds a range header to a request for a specified range.

AddRange(String, Int64, Int64)

向请求添加指定范围的范围标头。Adds a range header to a request for a specified range.

注解

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

AddRange(Int32)

向请求添加从请求数据的开始处或结束处的特定范围的字节范围标头。Adds a byte range header to a request for a specific range from the beginning or end of the requested data.

public:
 void AddRange(int range);
public void AddRange (int range);
member this.AddRange : int -> unit
Public Sub AddRange (range As Integer)

参数

range
Int32

范围的开始点或结束点。The starting or ending point of the range.

异常

rangeSpecifier 无效。rangeSpecifier is invalid.

无法添加范围标头。The range header could not be added.

示例

下面的代码示例向请求添加范围标头。The following code example adds a range header to the request.

// 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->Headers);

HttpWebRequest^ myHttpWebRequest2 = 
    (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com" ) );
myHttpWebRequest2->AddRange(-1000);
Console::WriteLine("Call AddRange(-1000)");
      Console::Write("Resulting Headers: ");
      Console::WriteLine(myHttpWebRequest2->Headers);

// 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.Headers.ToString());

// 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.Headers.ToString());
' 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())

注解

HttpWebRequest.AddRange 方法向请求添加一个字节范围标头。The HttpWebRequest.AddRange method adds a byte range header to the request.

如果 range 为正,则 range 参数将指定范围的起始点。If range is positive, the range parameter specifies the starting point of the range. 服务器应该开始从指定的 range 参数向 HTTP 实体中数据的末尾发送数据。The server should start sending data from the range parameter specified to the end of the data in the HTTP entity.

如果 range 为负数,则 range 参数将指定范围的结束点。If range is negative, the range parameter specifies the ending point of the range. 服务器应该开始将数据从 HTTP 实体中的数据开始发送到指定的 range 参数。The server should start sending data from the start of the data in the HTTP entity to the range parameter specified.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

HTTP 协议请求中的范围标头示例请求服务器发送前100个字节(从开始到字节位置99),如下所示: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

对于本示例,range 参数将是-99。For this example, the range parameter would be -99.

HTTP 服务器指示支持范围标头和接受范围标头。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

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(Int64)

向请求添加从请求数据的开始处或结束处的特定范围的字节范围标头。Adds a byte range header to a request for a specific range from the beginning or end of the requested data.

public:
 void AddRange(long range);
public void AddRange (long range);
member this.AddRange : int64 -> unit
Public Sub AddRange (range As Long)

参数

range
Int64

范围的开始点或结束点。The starting or ending point of the range.

异常

rangeSpecifier 无效。rangeSpecifier is invalid.

无法添加范围标头。The range header could not be added.

注解

HttpWebRequest.AddRange 方法向请求添加一个字节范围标头。The HttpWebRequest.AddRange method adds a byte range header to the request.

如果 range 为正,则 range 参数将指定范围的起始点。If range is positive, the range parameter specifies the starting point of the range. 服务器应该开始从指定的 range 参数向 HTTP 实体中数据的末尾发送数据。The server should start sending data from the range parameter specified to the end of the data in the HTTP entity.

如果 range 为负数,则 range 参数将指定范围的结束点。If range is negative, the range parameter specifies the ending point of the range. 服务器应该开始将数据从 HTTP 实体中的数据开始发送到指定的 range 参数。The server should start sending data from the start of the data in the HTTP entity to the range parameter specified.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

HTTP 协议请求中的范围标头示例请求服务器发送前100个字节(从开始到字节位置99),如下所示: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

对于本示例,range 参数将是-99。For this example, the range parameter would be -99.

HTTP 服务器指示支持范围标头和接受范围标头。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

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(Int32, Int32)

向请求添加指定范围的字节范围标头。Adds a byte range header to the request for a specified range.

public:
 void AddRange(int from, int to);
public void AddRange (int from, int to);
member this.AddRange : int * int -> unit
Public Sub AddRange (from As Integer, to As Integer)

参数

from
Int32

开始发送数据的位置。The position at which to start sending data.

to
Int32

停止发送数据的位置。The position at which to stop sending data.

异常

rangeSpecifier 无效。rangeSpecifier is invalid.

from 大于 tofrom is greater than to

-or- fromto 小于 0。from or to is less than 0.

无法添加范围标头。The range header could not be added.

示例

下面的代码示例向请求添加范围标头。The following code example adds a range header to the request.

// Create a New 'HttpWebRequest' object.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.contoso.com" ) );
myHttpWebRequest->AddRange( 50, 150 );
Console::WriteLine("Call AddRange(50, 150)");
      Console::Write("Resulting Request Headers: ");
      Console::WriteLine(myHttpWebRequest->Headers);

// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse() );

// Displays the headers in the response received
Console::Write("Resulting Response Headers: ");
      Console::WriteLine(myHttpWebResponse->Headers);

// Display the contents of the page to the console.
Stream^ streamResponse = myHttpWebResponse->GetResponseStream();
StreamReader^ streamRead = gcnew StreamReader( streamResponse );
array<Char>^ readBuffer = gcnew array<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 = gcnew String( readBuffer,0,count );
   Console::WriteLine( outputData );
   count = streamRead->Read( readBuffer, 0, 256 );
}
streamRead->Close();
streamResponse->Close();
myHttpWebResponse->Close();
      // Create a New 'HttpWebRequest' object .
      HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("http://www.contoso.com");
      myHttpWebRequest.AddRange(50,150);	
      Console.WriteLine("Call AddRange(50,150)");
      Console.Write("Resulting Request Headers: ");
      Console.WriteLine(myHttpWebRequest.Headers.ToString());

      // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
      HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();

// Displays the headers in the response received
Console.Write("Resulting Response Headers: ");
      Console.WriteLine(myHttpWebResponse.Headers.ToString());

      // 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 characters are :\n  ");	
      while (count > 0) 
      {
          String outputData = new String(readBuffer, 0, count);
          Console.WriteLine(outputData);
          count = streamRead.Read(readBuffer, 0, 256);
      }
      // Release the response object resources.
      streamRead.Close();
      streamResponse.Close();
      myHttpWebResponse.Close();
' A New 'HttpWebRequest' objetc is created.
Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create("http://www.contoso.com")
myHttpWebRequest.AddRange(50, 150)
Console.WriteLine("Call AddRange(50, 150)")
      Console.Write("Resulting Request Headers: ")
      Console.WriteLine(myHttpWebRequest.Headers.ToString())

' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

' Displays the headers in the response received
Console.Write("Resulting Response Headers: ")
      Console.WriteLine(myHttpWebResponse.Headers.ToString())

' 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)
    Console.WriteLine(outputData)
    count = streamRead.Read(readBuffer, 0, 256)
End While
' Release the response object resources.
 streamRead.Close()
 streamResponse.Close()
myHttpWebResponse.Close()

注解

HttpWebRequest.AddRange 方法向请求添加一个字节范围标头。The HttpWebRequest.AddRange method adds a byte range header to the request.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

请求前100个字节的 HTTP 协议请求中的范围标头示例如下: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

对于本示例,from 参数将指定为0,并且 to 参数将指定为99。For this example, the from parameter would be specified as 0 and the to parameter would be specified as 99. 此方法自动将范围说明符设置为 "bytes"。The range specifier is automatically set as "bytes" by this method.

HTTP 服务器指示支持范围标头和接受范围标头。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

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(Int64, Int64)

向请求添加指定范围的字节范围标头。Adds a byte range header to the request for a specified range.

public:
 void AddRange(long from, long to);
public void AddRange (long from, long to);
member this.AddRange : int64 * int64 -> unit
Public Sub AddRange (from As Long, to As Long)

参数

from
Int64

开始发送数据的位置。The position at which to start sending data.

to
Int64

停止发送数据的位置。The position at which to stop sending data.

异常

rangeSpecifier 无效。rangeSpecifier is invalid.

from 大于 tofrom is greater than to

-or- fromto 小于 0。from or to is less than 0.

无法添加范围标头。The range header could not be added.

注解

HttpWebRequest.AddRange 方法向请求添加一个字节范围标头。The HttpWebRequest.AddRange method adds a byte range header to the request.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

请求前100个字节的 HTTP 协议请求中的范围标头示例如下: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

对于本示例,from 参数将指定为0,并且 to 参数将指定为99。For this example, the from parameter would be specified as 0 and the to parameter would be specified as 99. 此方法自动将范围说明符设置为 "bytes"。The range specifier is automatically set as "bytes" by this method.

HTTP 服务器指示支持范围标头和接受范围标头。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

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(String, Int32)

向请求添加从请求数据的开始处或结束处计算的特定范围的 Range 标头。Adds a Range header to a request for a specific range from the beginning or end of the requested data.

public:
 void AddRange(System::String ^ rangeSpecifier, int range);
public void AddRange (string rangeSpecifier, int range);
member this.AddRange : string * int -> unit
Public Sub AddRange (rangeSpecifier As String, range As Integer)

参数

rangeSpecifier
String

范围说明。The description of the range.

range
Int32

范围的开始点或结束点。The starting or ending point of the range.

异常

rangeSpecifiernullrangeSpecifier is null.

rangeSpecifier 无效。rangeSpecifier is invalid.

无法添加范围标头。The range header could not be added.

注解

HttpWebRequest.AddRange 方法向请求添加范围标头。The HttpWebRequest.AddRange method adds a Range header to the request.

如果 range 为正,则 range 参数将指定范围的起始点。If range is positive, the range parameter specifies the starting point of the range. 服务器应该开始从指定的 range 参数向 HTTP 实体中数据的末尾发送数据。The server should start sending data from the range parameter specified to the end of the data in the HTTP entity.

如果 range 为负数,则 range 参数将指定范围的结束点。If range is negative, the range parameter specifies the ending point of the range. 服务器应该开始将数据从 HTTP 实体中的数据开始发送到指定的 range 参数。The server should start sending data from the start of the data in the HTTP entity to the range parameter specified.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

rangeSpecifier 参数通常指定为 "bytes",因为这是大多数 HTTP 服务器识别的唯一范围说明符。The rangeSpecifier parameter would normally be specified as a "bytes", since this is the only range specifier recognized by most HTTP servers. rangeSpecifier 参数设置为其他某个字符串可支持除字节(在 RFC 2616 中由 IETF 定义的字节范围说明符)以外的自定义范围说明符。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).

请求前100个字节的 HTTP 协议请求中的范围标头示例如下: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

对于本示例,rangeSpecifier 参数将指定为 "bytes",range 参数将为-99。For this example, the rangeSpecifier parameter would be specified as "bytes" and the range parameter would be -99.

HTTP 服务器指示对范围标头的支持在响应中包含 Accept 范围标头。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

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(String, Int64)

向请求添加从请求数据的开始处或结束处计算的特定范围的 Range 标头。Adds a Range header to a request for a specific range from the beginning or end of the requested data.

public:
 void AddRange(System::String ^ rangeSpecifier, long range);
public void AddRange (string rangeSpecifier, long range);
member this.AddRange : string * int64 -> unit
Public Sub AddRange (rangeSpecifier As String, range As Long)

参数

rangeSpecifier
String

范围说明。The description of the range.

range
Int64

范围的开始点或结束点。The starting or ending point of the range.

异常

rangeSpecifiernullrangeSpecifier is null.

rangeSpecifier 无效。rangeSpecifier is invalid.

无法添加范围标头。The range header could not be added.

注解

HttpWebRequest.AddRange 方法向请求添加范围标头。The HttpWebRequest.AddRange method adds a Range header to the request.

如果 range 为正,则 range 参数将指定范围的起始点。If range is positive, the range parameter specifies the starting point of the range. 服务器应该开始从指定的 range 参数向 HTTP 实体中数据的末尾发送数据。The server should start sending data from the range parameter specified to the end of the data in the HTTP entity.

如果 range 为负数,则 range 参数将指定范围的结束点。If range is negative, the range parameter specifies the ending point of the range. 服务器应该开始将数据从 HTTP 实体中的数据开始发送到指定的 range 参数。The server should start sending data from the start of the data in the HTTP entity to the range parameter specified.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

rangeSpecifier 参数通常指定为 "bytes",因为这是大多数 HTTP 服务器识别的唯一范围说明符。The rangeSpecifier parameter would normally be specified as a "bytes", since this is the only range specifier recognized by most HTTP servers. rangeSpecifier 参数设置为其他某个字符串可支持除字节(在 RFC 2616 中由 IETF 定义的字节范围说明符)以外的自定义范围说明符。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).

请求前100个字节的 HTTP 协议请求中的范围标头示例如下: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

对于本示例,rangeSpecifier 参数将指定为 "bytes",range 参数将为-99。For this example, the rangeSpecifier parameter would be specified as "bytes" and the range parameter would be -99.

HTTP 服务器指示对范围标头的支持在响应中包含 Accept 范围标头。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

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(String, Int32, Int32)

向请求添加指定范围的范围标头。Adds a range header to a request for a specified range.

public:
 void AddRange(System::String ^ rangeSpecifier, int from, int to);
public void AddRange (string rangeSpecifier, int from, int to);
member this.AddRange : string * int * int -> unit
Public Sub AddRange (rangeSpecifier As String, from As Integer, to As Integer)

参数

rangeSpecifier
String

范围说明。The description of the range.

from
Int32

开始发送数据的位置。The position at which to start sending data.

to
Int32

停止发送数据的位置。The position at which to stop sending data.

异常

rangeSpecifiernullrangeSpecifier is null.

from 大于 tofrom is greater than to

-or- fromto 小于 0。from or to is less than 0.

rangeSpecifier 无效。rangeSpecifier is invalid.

无法添加范围标头。The range header could not be added.

注解

HttpWebRequest.AddRange 方法向请求添加范围标头。The HttpWebRequest.AddRange method adds a Range header to the request.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

rangeSpecifier 参数通常指定为 "bytes",因为这是大多数 HTTP 服务器识别的唯一范围说明符。The rangeSpecifier parameter would normally be specified as a "bytes", since this is the only range specifier recognized by most HTTP servers. rangeSpecifier 参数设置为其他某个字符串可支持除字节(在 RFC 2616 中由 IETF 定义的字节范围说明符)以外的自定义范围说明符。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).

请求前100个字节的 HTTP 协议请求中的范围标头示例如下: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

对于本示例,rangeSpecifier 参数将指定为 "bytes",from 参数将为0,to 参数将为99。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.

HTTP 服务器指示对范围标头的支持在响应中包含 Accept 范围标头。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

在接受范围标头中指定的字符串为范围说明符,该说明符是在此方法的 rangeSpecifier 参数中指定的。The string specified in the Accept-Ranges header is the range-specifier that would be by specified in the rangeSpecifier parameter for this method.

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

AddRange(String, Int64, Int64)

向请求添加指定范围的范围标头。Adds a range header to a request for a specified range.

public:
 void AddRange(System::String ^ rangeSpecifier, long from, long to);
public void AddRange (string rangeSpecifier, long from, long to);
member this.AddRange : string * int64 * int64 -> unit
Public Sub AddRange (rangeSpecifier As String, from As Long, to As Long)

参数

rangeSpecifier
String

范围说明。The description of the range.

from
Int64

开始发送数据的位置。The position at which to start sending data.

to
Int64

停止发送数据的位置。The position at which to stop sending data.

异常

rangeSpecifiernullrangeSpecifier is null.

from 大于 tofrom is greater than to

-or- fromto 小于 0。from or to is less than 0.

rangeSpecifier 无效。rangeSpecifier is invalid.

无法添加范围标头。The range header could not be added.

注解

HttpWebRequest.AddRange 方法向请求添加范围标头。The HttpWebRequest.AddRange method adds a Range header to the request.

由于所有 HTTP 实体都在 HTTP 消息中表示为字节序列,因此字节范围的概念对于任何 HTTP 实体都是有意义的。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.

请求上的 Range 标头允许客户端请求仅接收 HTTP 实体中指定范围内的某个部分。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.

rangeSpecifier 参数通常指定为 "bytes",因为这是大多数 HTTP 服务器识别的唯一范围说明符。The rangeSpecifier parameter would normally be specified as a "bytes", since this is the only range specifier recognized by most HTTP servers. rangeSpecifier 参数设置为其他某个字符串可支持除字节(在 RFC 2616 中由 IETF 定义的字节范围说明符)以外的自定义范围说明符。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).

请求前100个字节的 HTTP 协议请求中的范围标头示例如下: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

对于本示例,rangeSpecifier 参数将指定为 "bytes",from 参数将为0,to 参数将为99。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.

HTTP 服务器指示对范围标头的支持在响应中包含 Accept 范围标头。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

在接受范围标头中指定的字符串为范围说明符,该说明符是在此方法的 rangeSpecifier 参数中指定的。The string specified in the Accept-Ranges header is the range-specifier that would be by specified in the rangeSpecifier parameter for this method.

如果服务器的响应标头中未收到 Accept 范围的标头,则服务器不支持范围标头。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. 不支持范围但可识别接受范围标头的服务器的 Accept 范围标头的示例如下所示: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

接收范围请求的响应时,只会分析与整个请求关联的 HTTP 标头,并通过 HttpWebResponse 类的属性使其可供使用。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.

另请参阅

适用于