HTTP communication

Contents:
Example 1: Basic retrieval
Example 2: Sending GET request
Example 3: Sending POST request

Example 1: Basic retrieval

Browser sends:

GET /form_test.html HTTP/1.1
Host: bilbo.cs.hendrix.edu:8888
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/10.04 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Server responds:

HTTP/1.1 200 OK
Date: Tue, 31 Jan 2012 15:40:14 GMT
Server: Apache/2.2.3 (CentOS)
Last-Modified: Tue, 31 Jan 2012 15:32:25 GMT
ETag: "18fc4d-183-4b7d4ab7eb440"
Accept-Ranges: bytes
Content-Length: 387
Connection: close
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<body>
<head>
  <meta charset="utf-8">
  <title>Form Examples</title>
</head>

<body>

<form method="get" action="http://localhost:8888/execute_get">
User ID: <input name="userid"></input><br />
Subject: <input name="subject"></input><br />
<input type="submit"></input>
</form>

<form method="post" action="http://localhost:8888/execute_post">
User ID: <input name="userid"></input><br />
Subject: <input name="subject"></input><br />
<input type="submit"></input>
</form>

</body>
</html>

Example 2: Sending GET retrieval

Web form:

<form method="get" action="/execute_get">
User ID: <input name="userid"></input><br />
Subject: <input name="subject"></input><br />
<input type="submit"></input>
</form>

Browser sends:

GET /execute_get?userid=bitdiddle&subject=Ones+and+Zeroes HTTP/1.1
Host: bilbo.cs.hendrix.edu:8888
Connection: keep-alive
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/10.04 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

Server responds:

HTTP/1.1 200 OK
Content-Type: application/json
Connection: close

{"success":true}

Example 3: Sending POST retrieval

Web form:

<form method="post" action="/execute_post">
User ID: <input name="userid"></input><br />
Subject: <input name="subject"></input><br />
<input type="submit"></input>
</form>

Browser sends:

POST /execute_post HTTP/1.1
Host: bilbo.cs.hendrix.edu:8888
Connection: keep-alive
Content-Length: 40
Cache-Control: max-age=0
Origin: null
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/10.04 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

userid=bitdiddle&subject=Ones+and+Zeroes

Server responds:

HTTP/1.1 200 OK
Content-Type: application/json
Connection: close

{"success":true}