home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2003 February
/
PCWorld_2003-02_cd.bin
/
Komunik
/
sambar
/
sambar52p.exe
/
CGITEST.DPR
next >
Wrap
Text File
|
1997-06-19
|
3KB
|
91 lines
program Cgitest;
{ This tests the win-cgi capabilities of a web server. For Delphi (all
versions).
The win-cgi programs receive three command line parameters. These are
filenames for interacting with the server.
The first parameter is the name of an INI file (doesn't have to be an .INI
file extension) containing information needed to process the request.
The second parameter is the name of a file containing data that was
POSTed by a form.
The third parameter is the file to where output needs to go to return
data to the web server.
This program simply reads the data from the file identified by the
first command line parameter and writes it to the file identified by
the third parameter. Some HTML formatting is included in the output.
Include this program in HTML Forms to see the results of submitting
the form, etc.
by Dave Wedwick
Phoenix Transit System
June, 1997 }
{$IFDEF WIN32}
{ 32-bit Delphi }
{$APPTYPE CONSOLE}
uses SysUtils;
{$ELSE}
{ 16-bit Delphi }
uses WinCrt, SysUtils;
{$ENDIF}
var
InStr: String;
InFile, OutFile: TextFile;
begin
{ If launched by the web server, there will be (at least) three
command line parameters. If there aren't, assume that this is
being launched by the command line and show a usage message. }
if ParamCount < 3 then begin
{ Write a message to the console }
WriteLn('CGI Test');
WriteLn('');
WriteLn('This tests the cgi-win capabilities of a web server.');
WriteLn('To test, copy this executable to the cgi-win area of the web');
WriteLn('server and reference it via the web browser.');
Exit;
end;
{ Open the third parameter for writing (output) }
Assign(OutFile, ParamStr(3));
Rewrite(OutFile);
{ Open the first parameter for reading the source from the server (input) }
Assign(InFile, ParamStr(1));
Reset(InFile);
{ Required header used by the server for processing }
WriteLn(OutFile, 'HTTP/1.0 200 OK');
WriteLn(OutFile, 'Content-type: text/html');
WriteLn(OutFile, ''); { <== Blank line is required }
{ Show the current time/date }
WriteLn(OutFile, 'Current Date/Time is <I>' + FormatDateTime('c', Now) +
'</I><BR>');
{ Simply read the input file, line by line, and write it to the
output file as pre-formatted HTML text (using the <PRE> tag) }
WriteLn(OutFile, '<PRE>');
while not EOF(InFile) do begin
ReadLn(InFile, InStr);
WriteLn(OutFile, InStr);
end;
WriteLn(OutFile, '</PRE>');
{ We're done. Close the files. When this .EXE finishes, the web server
then processes the output file for the client. }
CloseFile(InFile);
CloseFile(OutFile);
end.