This article assumes some (Not that much is required) experience in HTTP and sockets programming.
And shows in a straight forward way how to speak with HTTP Proxy servers.
Accessing a website through HTTP Proxy is pretty simple, it's almost like accessing a site directly. Let's assume that you want to make a connection to www.sourceforge.net, using a direct connection you would create a new socket, and use it to connect directly to the site. The sent headers would probably look like this:
Note that the HTTP client is said to be v1.1 compliant, so if your client is only meant to work with the 1.0 protocol, your headers will look a bit different. Using a proxy server to make the connection isn't very different, instead of connecting to www.sourceforge.net, you will make a connection to the HTTP proxy server (The port used for Proxy servers is usually 8080, but not always) The sent headers to a proxy server aren't very different, here's the syntax:
Notice that on the request line, and the Host header now specify the domain name as well, that tells the proxy server what site it should connect to. You should also notice the two extra headers at the bottom, these two should be used when connecting to a proxy server, to make sure the server is sending you the latest version of the document. Proxy Authentication:Some proxy servers require that the user authenticates itself, before it can use it. That is done with another header, named Proxy-Authorization. There are a couple of methods to authenticate to a proxy server, we're only going to talk about Basic, which is used by most proxy servers out there. Here's the syntax:Proxy-Authorization: Basic (base64)([username]:[password]) Don't forget that "Basic" is case-sensitive to a lot of Proxy servers, so make sure you type it correctly. The second part of the header, is the username and password, seperated by a colon, encoded in base64 (Base64 goes a bit out of the scope of this tutorial, but you can find a base64 encoder at the code sample of this tutorial). Just one sentence about Base64: it's being used much over the Internet because it's a simple binary/text data encryption/decryption techinque, which in generally makes 8 bit-bytes to 6 bit-bytes and vice versa. For example: If my username is "useme", and my password is: "test", the string that should be encoded is: useme:test After encoding, it'll look like this (in Base64 ofcourse): dXNlbWU6dGVzdA== Following the last example, if I would also like to authenticate under "useme" using the password "test", these will be the headers I'd send:
That's all you have to know in order to use HTTP Proxy servers in your programs, you may now download the sample I wrote and see some action going on! -->httpproxy.cpp<-- If you want to learn more about HTTP you can always read the RFC's at w3.org! Another link I recommend you to visit is HTTP Made Really Easy. Kudos to Saar(torando@goblineye.com) for writing this k3wl tutorial! |