Networking Tools: Thread-hot Internet Classes (int library)
#include <rw/toolpro/http.h> RWIHttpClient client(RWIHttpVersion_0_9());
thr, net, int, tls (and possibly std)
RWIHttpClient provides low-level access to the HTTP client-side protocol. The RWIHttpClient class maintains a finite state machine to enforce correct HTTP protocol action ordering. When methods are invoked in an inappropriate order, an RWIProtocolClientError exception is thrown.
The client, along with helper RWIHttpMethod and RWIHttpVersion classes, provides fine-grained control over HTTP communications. The execute method returns an RWIOUResult that can be redeemed for an RWIHttpReply. RWIHttpReply encapsulates the standard HTTP protocol reply messages. A reply can be queried for the result of the request, including indexing into any returned header information.
RWIHttpClient objects are lightweight. They are implemented using the interface-implementation pattern. The RWIHttpClient itself is really a handle to an implementation that performs the protocol interaction.
#include <iostream.h> #include <rw/toolpro/winsock.h> #include <rw/toolpro/http.h> #include <rw/toolpro/httpmeth.h> void main() { RWWinSockInfo info; RWIHttpClient client(RWIHttpVersion_1_0()); try { if (client.connect("www.roguewave.com")) { RWIHttpReply reply = client.execute(RWIHttpGet()); cout << reply << endl; if (reply.is2XX()) { // print out root document RWCString packet; while (!(packet = reply.portal().recv()).isNull()){ cout << packet << endl; } } } } catch (const RWxmsg& m) { cout << "Error : " << m.why() << endl; } }
RWIHttpClient();
Constructs a default invalid RWIHttpClient object. You must use the assignment operator to initialize the object, and then use the connect method to connect to an HTTP server.
RWIHttpClient(const RWIHttpVersion& ver);
Constructs a default RWIHttpClient object. You must use the connect method to connect to an HTTP server.
~RWIHttpClient();
Releases the memory used by the stored HTTP version.
RWIHttpClient(const RWIHttpClient& client);
Creates a copy of client. Self points to the same implementation and effectively becomes an additional handle to the protocol session. The previous implementation is released.
RWIHttpClient& operator=(const RWIHttpClient& other);
Sets self to the contents of other. The previous contents of self are lost.
RWIOUResult<RWBoolean> connect(const RWCString& host, int port=80);
Provides the connection method that allows an HTTP client to establish a connection session with an HTTP server. The host argument should be an IP address or host domain name. The port argument specifies the port on the server that the HTTP server process is using, normally 80. Success or failure is indicated by the RWBoolean, which is redeemable from the returned RWIOUResult.
RWIOUResult<RWIHttpReply> execute(RWIHttpMethod& method);
Sends method, which is a specific HTTP command, to the server and retrieves a response, if one exists. The function returns an RWIOUResult that can be redeemed for an RWIHttpReply.
If HTTP 0.9 has been used to construct the RWIHttpClient object, then each method in the RWIHttpReply object, except for the portal() method, is invalid. This is because HTTP 0.9 does not specify a response. However, you may be able to read data from the socket portal that is returned by the portal() method.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.