Internet Protocols Module User’s Guide : PART II Packages of the Internet Protocols Module : Chapter 5 The HTTP Package : Advanced Topics : Downloading Part of a Document
Downloading Part of a Document
When a download is interrupted before it is complete, your application needs to be able to retrieve only the part of the document that was not received. The HTTP/1.1 specification and the Rogue Wave HTTP classes enable you to do this through the HTTP Range header. Example 14 uses a simple GET request to retrieve the first 500 bytes of a document.
Example 14 – Retrieving part of a document with RWHttpClient
RWHttpClient client = RWHttpSocketClient::make();
// initialize, and connect the client…
 
RWHttpRangeHeader rangeHeader(0, 499); // 1
 
RWHttpHeaderList headerlist;
headerlist.addHeader(rangeHeader); // 2
 
RWHttpRequest request(RWHttpRequest::Get, "/", headerlist); // 3
 
client.submit(request);
 
// retrieve reply from the server
//1 Constructs an RWHttpRangeHeader that specifies the byte range to retrieved. In this case, it is the first 500 bytes of the document.
//2 Adds the Range header to the header list.
//3 Includes the Range header in the request object.
RWHttpAgent also enables you to retrieve a portion of a document. Example 15 shows how the previous example is implemented using RWHttpAgent.
Example 15 – Retrieving part of a document with RWHttpAgent
RWHttpAgent agent;
RWTIOUResult<RWHttpReply> replyIOU;
 
replyIOU = agent.executeGetRange("http://www.roguewave.com/",
0, 499);
For more information about partial downloads, see the ResumableDownload sample program distributed with the product.
NOTE >> Sample programs are located in the examples directory created for your installation. For more information, see Installing and Building Your SourcePro C++ Products and Building Your Applications.