Problem with CGI and .NET

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi.
I am trying to do a CGI in C#.
I have found code and explanation in
http://west-wind.com/weblog/posts/1143.aspx :

using System;
using System.IO;
using System.Collections;
using System.Text;

namespace CGITestApplication
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class CGITest
{
/// <summary>
/// The main entry point for the application.
/// </summary>
///

[STAThread]
static void Main(string[] args)
{

// *** Use this for debugging –
// Hit the link then attach debugger to this process
// and then pause to continue
// System.Threading.Thread.Sleep(30000);
// *** Loop through all the environement vars and write to
string

IDictionary Dict = Environment.GetEnvironmentVariables();
StringBuilder sb = new System.Text.StringBuilder();

foreach (DictionaryEntry Item in Dict)
{
sb.Append((string)Item.Key + " - " + (string)Item.Value
+ "\r\n");
}

// *** Read individual values
string QueryString =
Environment.GetEnvironmentVariable("QUERY_STRING");


// *** Read all the incoming form data both text and binary
string FormData = "";
byte[] Data = null;
///*
if (Environment.GetEnvironmentVariable("REQUEST_METHOD") ==
"POST")
{
Stream s = Console.OpenStandardInput();
BinaryReader br = new BinaryReader(s);
string Length =
Environment.GetEnvironmentVariable("CONTENT_LENGTH");
int Size = Int32.Parse(Length);
Data = new byte[Size];
br.Read(Data, 0, Size);
// *** don’t close the reader!

FormData = System.Text.Encoding.Default.GetString(Data,
0, Size);
}
//*/
Console.Write(
@"HTTP/1.1 200 OK
Content-type: text/html

<html>
Hello World

<pre>
<b>Environment and Server Variables:</b>
" + sb.ToString() + @"

<b>Form Vars (if any):</b>
" + FormData + @"
</pre>
</html>
");
}
}
}

I have compiled the code and put in a directory bellow wwwroot, with execute
permissions.
I have written the URL, and it didn't work; the answer was:
"
CGI Error
The specified CGI application misbehaved by not returning a complete set of
HTTP headers. The headers it did return are:

Unhandled Exception: System.ArgumentException: The parameter is incorrect.
(Exception from HRESULT: 0x80070057 (E_INVALIDARG))
"

When I try with unmanaged code (with a simpler source) I get the right answer.

Have you problems too with this C# code?


.



Relevant Pages

  • receiving an XML POST via CGI
    ... having the occasional problem getting my head around the "Ruby way". ... class that gives me most headaches is CGI.. ... Obviously at that stage REXML is packing in as the XML string is ... I'm wondering whether there is any "ruby magic" to the cgi.params call. ...
    (comp.lang.ruby)
  • Re: Problem with CGI and .NET
    ... I have compiled the code and put in a directory bellow wwwroot, ... The specified CGI application misbehaved by not returning a complete set of HTTP headers. ... Unhandled Exception: System.ArgumentException: The parameter is incorrect. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with CGI and .NET
    ... CGI Error ... HTTP headers. ... Unhandled Exception: System.ArgumentException: The parameter is incorrect. ... The code above is not correct CGI. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: CGI help
    ... integrity modifier,integm,System/Application,30,Customer ... after figuring out how CGI works in ruby ... ... The above will generate a body tag with a h1 tag and then close the body. ... The block passed to the form method must evaluate to a string which will ...
    (comp.lang.ruby)
  • Re: Cant use variable from cgi with hpricot
    ... A cursory examination of those strings reveals that they are not ... That's the string you are getting from cgi. ... special characters have to be 'untransformed' on the other side. ...
    (comp.lang.ruby)