HTTP works as a request/response system. Generally, a request will be like this:
[action] [path or object] [version]
[param1]: [value1]
[param2]: [value2]
[paramn]: [valuen]
[data, if a length is specified in content-length parameter; otherwise, nothing]
The parameter list always ends with two newlines, followed by data, if applicable.
The responses are:
[protocol] [response code] [response text]
[param1]: [value1]
[param2]: [value2]
[paramn]: [valuen]
[data, if a length is specified in content-length parameter; otherwise, nothing]
Here is an example from my browser, which shows a post thread and a redirection:
SENT:
POST /forum/index.php?action=post2;start=0;board=24 HTTP/1.1
Host: www.x86labs.org:81
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.x86labs.org:81/forum/index.php?action=post;board=24.0
Cookie: --- snip ---
Content-Type: multipart/form-data; boundary=---------------------------1164562419858532411229733600
Content-Length: 1610
-----------------------------1164562419858532411229733600
Content-Disposition: form-data; name="subject"
Test
-----------------------------1164562419858532411229733600
Content-Disposition: form-data; name="icon"
xx
-----------------------------1164562419858532411229733600
Content-Disposition: form-data; name="message"
test
--- snip ---
RECEIVED:
HTTP/1.1 302 Found
Date: Fri, 13 Apr 2007 23:59:29 GMT
Server: Apache/2.2.2 (Unix)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private
Pragma: no-cache
Location: http://www.x86labs.org:81/forum/index.php/topic,9077.new.html#new
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 26
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
SENT:
GET /forum/index.php/topic,9077.new.html HTTP/1.1
Host: www.x86labs.org:81
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.x86labs.org:81/forum/index.php?action=post;board=24.0
Cookie: --- snip ---
RECEIVED:
HTTP/1.1 200 OK
Date: Fri, 13 Apr 2007 23:59:29 GMT
Server: Apache/2.2.2 (Unix)
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Cache-Control: private
Pragma: no-cache
Last-Modified: Fri, 13 Apr 2007 23:59:29 GMT
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 7269
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=ISO-8859-1
--- snip ---
I wrote a really nice Java library that could handle sending and receiving commands, and all commands had a response (even if it was an error). It worked really nicely. It's so flexible that you can do a lot, and it compresses extremely well if bandwidth is a concern. It's also extremely easy to troubleshoot. I had a flag I could set to turn compression off for troubleshooting.