Technology CGI, the response headers and requests for CGI

CGI is the connection (or interface) between a form on a Web page and the Web server. It is the interface between the Web page or browser and the Web server that runs the program. CGI programs are requested like any other regular documents. The difference is that instead of returning a static document, the server executes a program and returns its output.

read string

echo Content-type: text/html

echo ""

echo query string: $string

echo "<p>"

echo $string | awk -F= '{print "Hello", $2, "!"}' | sed 's/+/ /'

Headers can describe: The size of the data; Another document that the server should return (that is, instead of returning a virtual document created by the script itself); HTTP status codes

Content-length:The length of the output stream. Implies binary data.

Content-type: The MIME content type of the output stream

Expires: Date and time when the document is no longer valid and should be reloaded by the browser

Location: Server redirection (can`t be sent as part of a complete header).

Pragma: Turns document caching on and off

Status: Status of the request (can`t be sent as part of a complete header).

Header lines don't have to be in any special order.They can be output in any order you like. The header block has to end with a blank line.

The way the server knows that you're done with your header information is that it looks for a blank line. Everything before the blank line is taken as header information; everything after the blank line is assumed to be data.

The request method is specified in the environment variable REQUEST_METHOD.

GET: the query string sent is placed in the environment variable QUERY_STRING for CGI script to process.

POST: the query string is sent by a separate stream and becomes the standard input to the CGI script. Note: when POST is used, the environment variables are set: CONTENT_LENGTH, CONTENT_TYPE.


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: