Board index » delphi » Q: CGI programming in Turbo Pascal?

Q: CGI programming in Turbo Pascal?

I would like to write a CGI executable using Turbo Pascal.
Are there any references on how to do this? I am at a loss
on how to handle both get/post forms, and more particular
on how I can read and parse the CGI input and how I can
create a HTML feedback page and send it back using Turbo Pascal
(for DOS, NOT under Windows).

Any hints are greatly appreciated!

Many thanks in advance,
Jochen Musch

(Please cc: your answer to jochen.mu...@uni-bonn.de).

 

Re:Q: CGI programming in Turbo Pascal?


Hi,

on Sun, 06 Feb 2000 at 17:02:34 o'clock, Jochen Musch wrote:

Quote
> Are there any references on how to do this? I am at a loss
> on how to handle both get/post forms, and more particular
> on how I can read and parse the CGI input and how I can
> create a HTML feedback page and send it back using Turbo Pascal
> (for DOS, NOT under Windows).

First of all, this is (of course) dependant on the HTTP server you are
using. I know of at least one server that handles CGI requests by
calling REXX scripts...

Under most servers, for example IIS from Microsoft, the server invokes
a program and redirects the program's standard output to a pipe of its
own.  All information about the request (for example IP address, form
contents, etc.) is encoded in environment variables. I don't think
that these mechanisms (output redirection, env. variables) work
between Windows and DOS programs, and since I assume that your HTTP
server does not run under DOS, I don't think you can use TP for
that. Anyway, all information you need should be available in the
server documentation.

Parsing the input strings is another topic. It's not too difficult,
but units to do it for you have already been written. As an example,
FPC comes with a CGI unit, which is described in the documentation. I
have also seen a unit for Delphi.

Quote
> (Please cc: your answer to jochen.mu...@uni-bonn.de).

Since my reply is in no way an ultimate answer, I didn't mail it.
You should read the replies in the news anyway, since netnews is not a
write-only medium.

 - Sebastian

Re:Q: CGI programming in Turbo Pascal?


Quote
Jochen Musch wrote:
> I would like to write a CGI executable using Turbo Pascal.
> Are there any references on how to do this? I am at a loss
> on how to handle both get/post forms, and more particular
> on how I can read and parse the CGI input and how I can
> create a HTML feedback page and send it back using Turbo Pascal
> (for DOS, NOT under Windows).

> Any hints are greatly appreciated!

1. Read the data submitted via "post" from STDIN. The length should be
in the enviroment variable 'CONTENT_LENGTH'.
2. Read the data submitted via "get" from the env var 'QUERY_STRING'.
3. Don't output directly to the screen. Be sure to write to STDOUT. At
first you have to writeln('Content-type: text/html'); writeln; (the nl's
are important) Then write your homepage.

I didn't use TP for CGI yet so I don't know if my hints above are
helpful. Note that most web servers don't run under DOS.
IIRC, there is a unit for cgi-programming with FPC on www.freepascal.org

I suggest using perl (www.perl.com) for cgi-programming because string
handling is _much_ easier. (and you need it for example when parsing the
Query_String.

Wolf

Other Threads