Creating a Request
The
RWHttpClient classes encapsulate HTTP requests within the helper class
RWHttpRequest. All HTTP requests must specify:
The method to execute on the server
The path to the document that the method will act on
The version of the HTTP protocol that the request conforms to
Any HTTP headers that are required by the type of request
Example 5 constructs an
HTTP GET request to the root document of the HTTP server. The request does not include any user-defined HTTP headers, however an
HTTP Host header is automatically added to the request before sending the request to the server. For more information about adding additional HTTP headers or modifying the default headers, see
Adding and Removing Headers. Example 5 – Creating a request
RWHttpRequest request(RWHttpRequest::Get, "/");
RWHttpRequest objects default to HTTP/1.1 formatted request, however the major and minor versions of the request can be set through member functions:
request.setVersion(1, 0);
This example converts the
RWHttpRequest into an HTTP/1.0 request with all of the restrictions associated with HTTP/1.0 requests. Unless a server specifically cannot accept HTTP/1.1 formatted requests, use the default.