RWIHttpAgentRWIAgent
Networking Tools: Thread-hot Internet Classes (int library)
#include <rw/toolpro/httpa.h> RWIHttpAgent agent("www.roguewave.com", RWIHttpVersion_1_0());
thr, net, int, tls (and possibly std)
RWIHttpAgent is a class that simplifies performing the most common HTTP requests. The RWIHttpClient class is used under the hood to perform these requests. RWIHttpAgent handles more of the details of the HTTP protocol than the RWIHttpClient class. However, it doesn't provide the flexibility of the client class.
RWIHttpAgent currently supports both HTTP 0.9 and HTTP 1.0 protocols. If a user attempts to initiate a transaction using an agent class of HTTP Version 0.9 and such an action is not valid or available in Version 0.9, an RWxmsg exception is thrown.
The non-default constructor of RWIHttpAgent stores connection information. The methods interact with an HTTP server by connecting, performing the requested action, and disconnecting. Multiple transactions may be performed before an RWIHttpAgent object is destroyed.
RWIHttpAgent objects are lightweight. They are implemented using the interface-implementation pattern. A handle to an implementation actually performs the protocol interaction.
#include <iostream.h> #include <rw/cstring.h> #include <rw/toolpro/sockport.h> #include <rw/toolpro/portstrm.h> #include <rw/toolpro/winsock.h> #include <rw/toolpro/httpa.h> void main() { RWWinSockInfo info; try { // Construct an agent to talk with our known // HTTP server RWIHttpAgent agent("www.roguewave.com", RWIHttpVersion_1_0()); // Create an RWTime of July 4, 1996 to check against RWTime t(RWDate(4, 7, 1996)); // Check whether the root document has been changed // since t RWBoolean changedSince = agent.isNewer("/", t); if (changedSince) { cout << "Better retrieve the file again" << endl; } } catch (const RWxmsg& m) { cout << "Error : " << m.why() << endl; } }
RWIHttpAgent();
Constructs a default RWIHttpAgent object, which is invalid until initialized. Use the assignment operator to initialize a default RWIHttpAgent object. Using the uninitialized default object causes an exception to be thrown.
RWIHttpAgent(const RWCString& host, const RWIHttpVersion& ver);
Constructs an RWIHttpAgent that is ready to use. The host argument is the domain name of the HTTP server of interest. The ver argument specifies which HTTP version to use.
RWIOUResult<RWSocketPortal> get(const RWCString& httpPath="/");
Returns an RWIOUResult that can be redeemed for an RWSocketPortal. The socket portal can then be used to retrieve the body of the HTTP document specified by the httpPath argument. The root document is the default URL. Document retrieval is accomplished by sending a GET request to the server with the requested document specified in httpPath. No header information is attached to the request.
RWIOUResult<RWBoolean> isNewer(const RWCString& httpPath, const RWTime& t);
Returns an RWIOUResult that can be redeemed for an RWBoolean. The RWBoolean indicates whether the document at the specified httpPath has been modified more recently than the passed-in time t. The comparison is accomplished by sending a GET request to the server and attaching an If-Modified-Since header with the value of the passed-in time t.
This method is not available in HTTP Version 0.9. Attempting to use it with that version causes an exception to be thrown.
RWIOUResult<RWSocketPortal> post(const RWCString& httpPath, const RWCString& postData="");
Returns an RWIOUResult that can be redeemed for an RWSocketPortal. The socket portal can then be used for posting. This action is accomplished by sending a POST request to the server with the specified httpPath. postData is attached as the body of the request. By default, postData is empty.
This method is not available in HTTP Version 0.9. Attempting to use it with that version causes an exception to be thrown.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.