These programs are most often served from a directly called /cgi-bin/ but
CGI sends most information concerning an http request from the server to the program via OS Environment Variables. The remaining information (usually only used for the POST data transfer method) is sent to the stdin of the program and will be of a length given in the %CONTENT_LENGTH% variable.
Here is an example of the information sent to a CGI program (the Win32AsmCGI program)
%SERVER_SOFTWARE% = Microsoft-IIS/4.0 %SERVER_NAME% = 192.168.0.5 %GATEWAY_INTERFACE% = CGI/1.1 %SERVER_PROTOCOL% = HTTP/1.1 %SERVER_PORT% = 80 %REQUEST_METHOD% = POST %PATH_TRANSLATED% = h:\Inetpub\wwwroot %SCRIPT_NAME% = /cgi-bin/asmcgi.exe %QUERY_STRING% = get=still %REMOTE_HOST% = 192.168.0.6 %REMOTE_ADDR% = 192.168.0.6 %CONTENT_TYPE% = application/x-www-form-urlencoded %CONTENT_LENGTH% = 47 %HTTP_ACCEPT% = application/msword, application/vnd.ms-excel, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* %HTTP_USER_AGENT% = Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)
Output from the script is returned to stdout and in order to tell the server what kind of document you are sending back, whether it be a full document or a reference to one, CGI requires you to place a short header on your output. This header is ASCII text, consisting of lines separated by either linefeeds or carriage returns (or both) followed by a single blank line. The output body then follows in whatever native format.
For example, to send back HTML to the client, your output should read:
Content-type: text/html <HTML><HEAD> <TITLE>output of HTML from CGI script</TITLE> </HEAD><BODY> <H1>Sample output</H1> What do you think of <STRONG>this?</STRONG> </BODY></HTML>
|file: /Techref/inet/cgi.htm, 2KB, , updated: 2001/6/21 12:36, local time: 2021/4/16 05:06,
|©2021 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.massmind.org/techref/inet/cgi.htm"> Internet Web Server CGI</A>
|Did you find what you needed?|
Welcome to massmind.org!
Welcome to www.massmind.org!