the CGI for IIS (PWS) servers

Hello, Experts.
I have problems with making CGI. So, I have D4 with internet components. So, I am loking for information about building CGI applications. All kind.. from counters till shoping things.

Thank you for your help.
Sandis Viksna.
LVL 1
sviksnaAsked:
Who is Participating?
 
geobulCommented:
Hi,

Setting cookies :

procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  slCookies : TStringList;
  login, passw : string;
begin
  slCookies := TStringList.Create;
  ...
  { reading values from somewhere - from Request here }
  login:=Request.ContentFields.Values['login'];
  passw:=Request.ContentFields.Values['passw'];
  .....
  { adding cookies to string list }
  slCookies.Add('login='+login);
  slCookies.Add('passw='+passw);
  { set cookies in Response }
  Response.SetCookieField(slCookies,'','',Request.Date-1,False);
  .......
  slCookies.Free;
end;


Reading cookies:

procedure TWebModule1.WebModule1WebActionItem2Action(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
  login, passw : String;
begin
  ...
  login := Request.CookieFields.Values['login'];
  passw := Request.CookieFields.Values['passw'];
  ...
end;

Regards, Geo
0
 
ckanetaCommented:
create a Delphi console application, replace the typical source code with something like this:

program cgi;
{$apptype console}

uses Sysutils;

begin
 writeln('HTTP/1.0 200 OK');
 writeln('CONTENT-TYPE: TEXT/HTML');
 writeln('<html><head>');
 writeln('<title>blah blah</title>');
 writeln('</head><body>');
 writeln('</body></html>');
end.
basically from Cantu's book.
I can try to dig up a sample and send it if you like
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
mike_tippingCommented:
remember to enable CGI on the website in IIS (well it caught me out for a while)
0
 
sviksnaAuthor Commented:
ckaneta,
it would be nice. thank you.

Sandis.
0
 
ckanetaCommented:
okay, either write to me at ckan1010@aol.com and I'll send it in a reply or get it from here

members.xoom.com/kaneta/dwnld/cgistuff.zip

~ or ~

members.xoom.com/kaneta
and go to the 'stuff' page

0
 
sviksnaAuthor Commented:

the code
program response;
{$apptype console}

uses Sysutils;

begin
 writeln('HTTP/1.0 200 OK');
 writeln('CONTENT-TYPE: TEXT/HTML');
 writeln('<html><head>');
 writeln('<title>blah blah</title>');
 writeln('</head><body> here it is dude');
 writeln('</body></html>');
end.

----------------------
the result
-----------------------
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:


HTTP/1.0 200 OK
CONTENT-TYPE: TEXT/HTML


here it is dude
-------------------------

can u help me?
0
 
EpsylonCommented:
The second writeln is not right. Change or remove it and try again.
0
 
geobulCommented:
Hi,

Select 'File-New-Web Server Application' from Delphi main menu and then 'CGI Stand-alone Executable'. This way you have created new CGI project with WebModule. In WebModule you can add Action Items for different HTTP methods like GET and POST and for different 'commands' after the name of your CGI script, defined in the calling HTML page like
....
<FORM METHOD=POST ACTION="/scripts/MyScript.exe/login">
.....
where 'MyScript.exe' is the name of the script and '/login' is the 'command', corresponding with Action Item with PathInfo property = /login.
  There are Request object containing all information about the client's browser request and Response object which Content property your program has to fill with HTML page and send back using SendResponse method.

  You have to build the exe and copy to the scripts directory of the Web server.

It's not so hard stuff as it sounds.

Regards, Geo
0
 
sviksnaAuthor Commented:
The advice one step up is ok. But how to do with thing like session() in ASP. How i can pass the data in novisual mode, i meant with this, that data isn't visible into the location bar, like
some.exe?name=john&regnum=32434234

couse, these params are constants for current user in all pages, but i don't wana write them in the HTML code as Hiden object (<input type="hiden"..) security for...

so, is there any solution for this?

Sandis.
0
 
EpsylonCommented:
Use cookies. This is how asp sessions work...
0
 
sviksnaAuthor Commented:
hi, geo, again

{ reading values from somewhere - from Request here }
  login:=Request.ContentFields.Values['login'];
  passw:=Request.ContentFields.Values['passw'];


is that like value
cgi-bin/myapp.exe/login=loginame&passw=somepass


am i right?
0
 
geobulCommented:
Hi,

  I'm using POST method in my example and login and pass values are in the content property of the request (INPUT text/password html tags and a button).
  You are using GET method in your example and the info is in the query property of the request. So the code will be:

login:=Request.QueryFields.Values['login'];
  passw:=Request.QueryFields.Values['passw'];

Regards, Geo
0
 
sviksnaAuthor Commented:
This was one of moust useable anwers.
Thank You.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.