HttpWebRequest.AddRange Method (Int32)
2012-07-16 17:44
721 查看
public void AddRange(
int range
)
RemarksThe 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.
Examples
The following code example adds a range header to the request.
C#
C++
VB
// 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());
相关文章推荐
- HttpWebRequest.AddRange 支持long类型
- 关于HttpWebRequest.AddRange()方法的参数
- NET(C#):使用HttpWebRequest头中的Range下载文件片段
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
- NET(C#):使用HttpWebRequest头中的Range下载文件片段
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method
- NET(C#):使用HttpWebRequest头中的Range下载文件片段
- web_add_auto_header("x-requested-with", "XMLHttpRequest "); 在LR中的作用
- HttpWebRequest.Method 属性
- 关于loadrunner使用web_add_header添加HTTP信息头(比如Content-Type,token等)和使用web_custom_request()提交json数据
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
- 关于loadrunner使用web_add_header添加HTTP信息头(比如Content-Type,token等)和使用web_custom_request()提交json数据
- springMVC:org.springframework.web.servlet.PageNotFound.handleHttpRequestMethodNotSupported Request method 'POST' not supported
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supporte
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
- org.springframework.web.servlet.PageNotFound handleHttpRequestMethodNotSupportedWARNING: Request met
- HttpWebRequest.Method属性研究
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported解决!
- Web crash:The method getDispatcherType() is undefined for the type HttpServletRequest
- 'System.Web.HttpRequest.QueryString' denotes a 'property' where a 'method