external next up previous contents index
Next: 8.8 [TECFAMOO] ``E_WEB'' Tutorial Up: 8.7 A crash course Previous: The HTTP 1.0 Protocol

Introduction to CGI

 

User data from the client are transferred either in the URL (with the GET method) or in the body of the request (with the POST method). See section 8.7.1 for more details.

Here is a typical GET request from our WOO interface:

GET http://tecfamoo.unige.ch:7777/1202?verb=options&do=Do+it%21 HTTP/1.0
You can see that the ? is used to separate contents from the URL.

Now let's have a look a character encoding produced when sending user data with the POST method. The user data are transferred with a string that will look like this:

name=Daniel&age=old&string=Hello+there+%21
for a form input like this:
<input type="text" size=20 name=name><br>
Your age:
<input type="radio" name=age value="young" checked> &lt; 30
<input type="radio" name=age value="old"> &gt; 30
<p>Input something please:<br>
<input type="text" name=string size=60><br>
For each named widget we will receive a
   <name>=<value>
pair and all pairs will be separated by & signs as you can figure out from the example above.

Special signs like ``/'', the space and the end-of-line character are also encoded specially. The space character is usually done with a ``+'', but most other characters use a hex encoding. E.g. the ``!'' sign is encoded as %21. Cgi-bin scripts must decode those strings.

The string containing variable=value pairs is usually passed to a CGI program through UNIX environment variables (in the case of GET) or the standard input (in the case of POST). In E_Web the query string is given as an argument to API verbs like http_request or cgi_query. Other environment variables (both in the UNIX world and the MOO) can be used by the CGI program to retrieve additional information, e.g. content length, the remote host and various client information.

All you need to do now is producing the Virtual Document passed back to the client. With a typical UNIX environment you just write HTML lines to the standard output. Usually the server will produce minimal response header for you, but you can do it yourself too. The minimal requirement with most servers is that you write a content type header line, e.g.

  Content-type: text/html

In the next section 8.8 you will learn how to do this with E_Web.


next up previous contents index external
Next: 8.8 [TECFAMOO] ``E_WEB'' Tutorial Up: 8.7 A crash course Previous: The HTTP 1.0 Protocol

Daniel K. Schneider
Thu Apr 17 12:43:52 MET DST 1997