Starting with HTTP version 1.0, requests and responses can accommodate header fields, which consist of a field name followed by a colon, a single space, and the value associated with the field. Detailed information is in RFC 1945, which is available at the Web sites listed in the bibliography.
Class RWIHttpMethod, which is the base class of all HTTP commands, provides methods to include header information as part of a command request. They are:
void addHeader(const RWIHttpHeaderBase& hdr); //1 void addHeader(const RWCString& label, const RWCString& value); //2
//1 | Adds hdr to an internal list of headers that are attached to a request. In the Internet Protocols package, a series of header helper classes are provided as a convenience for some common header fields. They are RWIHttpGenericHeader, RWIHttpDateHeader, RWIHttpFromHeader, RWIHttpIfModifiedSinceHeader, RWIHttpUserAgentHeader, and RWIHttpContentLengthHeader for generic, Date, From, If-Modified-Since, User-Agent, and Content-Length headers respectively. Note that some of these header classes can also be used in responses and body description. |
//2 | Formats the passed-in data as label: value, and adds the result to an internal list of headers attached to a request. This method lets you insert any header field in the internal header list. No validity check is performed. |
The following sample code demonstrates how headers can be constructed as part of an HTTP GET request.
void main() { try { RWIHttpVersion_1_0 v10; RWIHttpClient client(v10); RWIHttpGet getCmd; // get the root document getCmd.addHeader(RWIHttpUserAgentHeader("HTTP 1.0 client")); getCmd.addHeader("From", "me@roguewave.com"); bool b = client.connect("www.roguewave.com"); RWIHttpReply reply = client.execute(getCmd); ... // retrieve data of the root document ... } catch (const RWxmsg& msg) { cout << "Error : " << msg.why() << endl; } }
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.