cgi

  • Thread starter Thread starter Robbie Leatherbarrow
  • Start date Start date
R

Robbie Leatherbarrow

Hi All,

I have a slight problem needing to produce a simple application which needs
to run as a cgi.

Unfortunately due to historical reasons the application needs to be an exe
hence the use of asp.net is no good.

The problem I have is using a response and request functionality in vb.net
for use as a cgi. (Should I create this as a console application?). I will
only really need a response.redirect and request.form. Basically going to
read information out of a form and process the information then jump to a
page depending on the process.

Any clues please.

Thanks

Robbie
 
Robbie said:
Hi All,

I have a slight problem needing to produce a simple application which needs
to run as a cgi.

Unfortunately due to historical reasons the application needs to be an exe
hence the use of asp.net is no good.

The problem I have is using a response and request functionality in vb.net
for use as a cgi. (Should I create this as a console application?). I will
only really need a response.redirect and request.form. Basically going to
read information out of a form and process the information then jump to a
page depending on the process.

Any clues please.

Thanks

Robbie

Well Robbie, I haven't done any serious CGI programming for quite some
time... But I'll take a stab at this :)

I'm not really sure if you can get the Request/Response objects to work
or not outside of an ASP.NET app - so I'll tell you how to do it the old
fashioned way, though there are classes in the framework that can make
some of this easier...

First, you definately want to make this a console application. Form
there your going to need to know how the data is beign based to your
application - via a GET or a POST. You can find that out by looking at
the environment variable REQUEST_METHOD. The method determines how the
data is passed in. If it is GET, then the data was passed in as part of
the URL, so you get it from the environment variable QUERY_STRING. If
it is POST then the data was passed via stdin, so you would then look at
the CONTENT_LENGTH environment variable to find out how much data to
read, and then you would do something like:

Dim contentLength As Integer = _
CInt(System.Environment.GetEnvironmentVariable("CONTENT_LENGTH"))
Dim buffer(contentLength - 1) As Char

Console.In.ReadBlock(buffer, 0, contentLength)
Dim content As String = new String(buffer) ' convert it to a string

Of course, you would probably want to check the return valueof the read,
to make sure there were no errors :)

Once you have the data, you then have to parse it and process it. The
strings are encoded, so you'll want to take a look at the
System.Web.HttpUtility class to help with the parsing and decoding
(particlarly the UrlDecode method).

Then writting back the data is pretty easy... Especially since your
just doing a redirect. That is a simple, console.writeline with the
proper header:

Console.WriteLine("Location: {0}", YourUrlString)
Console.WriteLine() ' let the server know were done.

Anyway, that's the basics of how CGI works...

HTH,
Tom Shelton
 
Back
Top