Sending Requests through HTTP Proxies
When HTTP requests are sent to an HTTP proxy (such as a firewall) that forwards the request to the target HTTP server, your application must include the following steps:
The client must connect to the proxy HTTP server instead of the actual HTTP server.
The request must contain a
Host header that points to the actual server that the request is intended for.
Example 19 shows a simple
GET request executed through a proxy HTTP server.
NOTE: Servers and files shown in the code might not exist and are included as examples only.
Example 19 – Sending a request through a proxy HTTP server
RWHttpClient client = RWHttpSocketClient::make();
RWCString proxyServer = "proxy.somehost.com"; // 1
RWCString actualServer = "www.perforce.com"; // 2
RWCString path = "/";
client.connect(proxyServer); // 3
RWHttpHostHeader hostHeader(actualServer); // 4
RWHttpHeaderList headerlist;
headerlist.addHeader(hostHeader); // 5
RWHttpRequest request(RWHttpRequest::Get, path, headerlist); // 6
client.submit(request); // 7
// retrieve reply from the server...
Issuing an HTTP request through a proxy HTTP server using the
RWHttpAgent classes uses a slightly different process for specifying the proxy and actual servers to use:
RWHttpAgent agent;
agent.executeGet(
"http://proxy.somehost.com/http://www.perforce.com/");