8. HTTP and Server-Side Processing


  1. HTTP/1.0 Overview
  2. HTTP Interaction
  3. HTTP/1.1 Persistent Connections
  4. Pipelining
  5. HTTP Client Requests
  6. HTTP Server Responses
  7. Some request and response headers
  8. Example of request and response
  9. Example using HTML form
  10. HTML for form
  11. HTML form processing
  12. Server-side processing technologies
  13. PHP
  14. PHP code for www-inventor.php
  15. Processing XML with PHP (1)
  16. Processing XML with PHP (2)
  17. Retrieving JSON
  18. REST
  19. PHP and JSON
  20. PHP code for Nobel Prizes (1)
  21. PHP code for Nobel Prizes (2)
  22. PHP code for Nobel Prizes (3)
  23. Links to more information

8.1. HTTP/1.0 Overview

8.2. HTTP Interaction

8.3. HTTP/1.1 Persistent Connections

HTTP persistent connections

8.4. Pipelining

HTTP pipelining

8.5. HTTP Client Requests

8.6. HTTP Server Responses

8.7. Some request and response headers

8.8. Example of request and response

Machine responses are this colour below:

Peter-Woods-MacBook-Pro:~ ptw$ telnet www.dcs.bbk.ac.uk 80
Trying 193.61.29.21...
Connected to www.dcs.bbk.ac.uk.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Fri, 18 Nov 2011 17:44:06 GMT
Server: Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8o DAV/2 SVN/1.6.5 mod_fcgid/2.3.6 mod_perl/2.0.4 Perl/v5.8.4
Connection: close
Content-Type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Computer Science and Information Systems Birkbeck University of London</title>

...

</body>
</html>

Connection closed by foreign host.
Peter-Woods-MacBook-Pro:~ ptw$

8.9. Example using HTML form

8.10. HTML for form

<form action="http://titan.dcs.bbk.ac.uk/~ptw/teaching/IWT/server/www-inventor.php"
      method="GET">
  <label for="www-inventor">Who invented the WWW (surname only)?</label>
  <input type="text" id="www-inventor" name="inventor" />
  <input type="submit" value="Submit answer" />
  <input type="reset" value="Erase answer" />
</form>

8.11. HTML form processing

8.12. Server-side processing technologies

8.13. PHP

8.14. PHP code for www-inventor.php

<html>
<head><title>WWW Inventor</title></head>
<body>
<h1>
<?php
if ($_GET['inventor'] == "Berners-Lee")
   echo "Congratulations, you answered correctly.";
else
   echo "Sorry, the correct answer is Berners-Lee.";
?>
</h1>
</body>
</html>

8.15. Processing XML with PHP (1)

8.16. Processing XML with PHP (2)

8.17. Retrieving JSON

8.18. REST

8.19. PHP and JSON

8.20. PHP code for Nobel Prizes (1)

<html>
<body>
<h1>Nobel Prize Winners</h1>
<?php
  $year = $_GET['year'];
  if ($year >= 1901 && $year <= 2017) {
    $url = 'http://api.nobelprize.org/v1/prize.json?year=' . $year;
    $string = file_get_contents($url);

    # Read the JSON output into an associative array
    $result  = json_decode($string, true);

    print "<p>In $year, the prizes were awarded as follows:</p><ul>\n";
     ...  # see next slide
    print "</ul>";
  }
  else {
    print "<p>Year value out of range; years range from 1901 to 2017</p>";
  }
?>
</body>
</html>

8.21. PHP code for Nobel Prizes (2)

returned JSON data is as follows (for year 1991):

{"prizes":
 [
  {"year":"1991",
   "category":"physics",
   "laureates":[
    {"id":"141",
     "firstname":"Pierre-Gilles",
     "surname":"de Gennes",
     "motivation":"...",
     "share":"1"}]},
  {"year":"1991",
   "category":"chemistry",
   "laureates":[
    {"id":"276",
     "firstname":"Richard R.",
     "surname":"Ernst",
     "motivation":"...",
     "share":"1"}]},
  {"year":"1991",
   "category":"medicine",
   "laureates":[
    {"id":"444",
     "firstname":"Erwin",
     "surname":"Neher",
     "motivation":"...",
     "share":"2"},
    {"id":"445",
     "firstname":"Bert",
     "surname":"Sakmann",
     "motivation":"...",
     "share":"2"}]},
  {"year":"1991",
   "category":"literature",
   "laureates":[
    {"id":"668",
     "firstname":"Nadine",
     "surname":"Gordimer",
     "motivation":"...",
     "share":"1"}]},
  {"year":"1991",
   "category":"peace",
   "laureates":[
    {"id":"553",
     "firstname":"Aung San Suu Kyi",
     "motivation":"...",
     "share":"1",
     "surname":""}]},
  {"year":"1991",
   "category":"economics",
   "laureates":[
    {"id":"707",
     "firstname":"Ronald H.",
     "surname":"Coase",
     "motivation":"...",
     "share":"1"}]}
 ]
}

8.22. PHP code for Nobel Prizes (3)

8.23. Links to more information

HTTP is covered briefly in Section 4.6 of [Comer]. Section 7.3 of [Tanenbaum] covers HTML forms and HTTP, and mentions CGI and PHP. Servlets are covered in Chapter 9 and JSP in Chapter 10 of [Moller and Schwartzbach]. Server-side processing of XML using PHP (and VB.NET) is covered in Chapters 11 (12) and 13 in [Jacobs].