Page 1 of 2

CGI on Windows 2003 hosting

Posted: Fri Feb 23, 2007 11:22 am
by Jordi
I'm beginning developing CGI application but with my first program, my Hello world", I have gotten from my hosting this error message:

"CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers"

or in Spanish version:

"La aplicación CGI especificada puede comportarse de forma anormal si no recibe un conjunto completo de encabezados HTTP."

Anyone knows why?
In my Xampplite on WinXP all it's OK. I will try later on IIS in WinXP.

Thanks.

Posted: Fri Feb 23, 2007 11:37 am
by Tommeh
Its because your CGI application isnt returning the correct headers the client, what you need to do, is work out how many bytes your output is going to be, so use a memory buffer or a string and then work out the length of it then say your output command is Output(string$)

Output("Content-Length: "+Str(ContentLength) + Chr(13) + Chr(10))
Output(Chr(13) + Chr(10) + Chr(13) + Chr(10))

This then should conform to a standard http response.

Posted: Fri Feb 23, 2007 12:40 pm
by Jordi
Thanks Tommeh but I have upload the CGI example of S. Rings and it says the same, same error. I think his example it's ok, isnt' it?

Is it necessary to generate the html code in a buffer, then coount the chars and send when? before, after the page?

Excuse me for this kind of question but I am starting :oops:

Thanks.

Posted: Fri Feb 23, 2007 2:18 pm
by Pantcho!!
Well 2 things!

1. you can also try Paul lib here:

http://www.reelmedia.org/pureproject

goto the libs section where you can download the cgi lib, and test his examples.

2. does your host allows you to use uploaded EXE?? as cgi?
that can be a very intrested info!

Posted: Fri Feb 23, 2007 2:30 pm
by yoxola
Windows 20003 :shock:

I'm going to join a time travel...

Posted: Fri Feb 23, 2007 2:33 pm
by Jordi
Can anyone send me a cgi to test? I don't know if I do something wrong, some "hello world"?

Host says that upload cgi to cgi-bin is possible so I think this is not the problem Pantcho, but I am not 100% sure.

Thanks.

Posted: Fri Feb 23, 2007 4:58 pm
by Thalius
IIS is very strict regarding header checks:

Try something like:

Code: Select all

print 'Status: 200 OK'
print 'Content-type: text/html'
print

print '<HTML><HEAD><TITLE>Hello CGI</TITLE></HEAD>'
print '<BODY>'
print '<H1>This is a header</H1>'

print '<p>' #this is a comment
print 'See this is just like most other HTML'
print '<br>'
print '</BODY>'
a header typically is ended with 2 return codes also. hence the empty print after content type - evtl add another to it and try.

EDIT: The thing is that the header has to be correct. Aka Google for it a bit theres similar problems with perl, pyton and other languages runnign as cgi under IIS.

Bit in a hurry or ill make an example but this should be easy enough ;)

Good Luck, Thalius

Posted: Fri Feb 23, 2007 10:09 pm
by Tommeh
Yes you count the html and send the header first, then send the rest, this lets the client know how much data it needs to receive

Posted: Sun Feb 25, 2007 9:40 pm
by Jordi
2 Tommeh: Thanks. Then I understand I have to send number of chars to be sent, then the header and the html code. Is this correct?

2 Thalius: "Print" is the same in this case to sent out the chars, correct? But as Tommeh and other say, it's necessary to send the number of chars before, or not?

2 Pantcho: Yes Paul library is nice and easy to use, I think because I have no tried it because it's a 3.94d version and I want to develop in 4.02, but how it would be an easy example with it to try my hosting?

Thanks all. I continue trying...

Posted: Mon Feb 26, 2007 1:13 am
by Paul
Jordi wrote: 2 Pantcho: Yes Paul library is nice and easy to use, I think because I have no tried it because it's a 3.94d version and I want to develop in 4.02, but how it would be an easy example with it to try my hosting?

:?: :?: :?: :?:

http://www.reelmedia.org/cgi-bin/PurePr ... s&sub=ASM4

Posted: Mon Feb 26, 2007 1:14 am
by Tommeh
Seems you don't have to use the content length

This was a lil bit of source from a program i done ages ago and i was using El_Choni's CGI library and looks like i never used content length, but it worked :)

Code: Select all

  StdOut("<html><head>")
  StdOut("<meta http-equiv="+Chr(34)+"content-Type"+Chr(34)+" content="+Chr(34)+"text/html; charset=windows-1252"+Chr(34)+">")
  StdOut("")
  StdOut("<title>PureBasic Source Code Dump! (PB-SCD) ["+UnIID.s+"]</title>")
  StdOut("</head>")
StdOut auto adds the Chr 13 + 10 automatically, this is needed :)

Posted: Mon Feb 26, 2007 9:22 am
by Jordi
Continuing my personal battle with CGI, I have tested in my WinXP with IIS 5.1 and all go fine, the same with Xampp (Lite). Now I need a local Win 2003 Server to test with IIS 6.

2 Paul: My apologizes. I was wrong, excuse me. Then I will try with your lib, for sure because I don't have too much time to develop from 0 :wink:

2 Tommeh: OK, I will try.

A question: Does CGI need some dll or any other lib or resource to run on the server?

Many thanks to everyone.

Posted: Mon Feb 26, 2007 11:40 am
by Tommeh
No none at all, but the account your running it under does need executable permissions.

For example you can use php as a CGI executable, when a request for a .php file happens, IIS or Apache or etc.. passes along the file name as a parameter to say C:\php\bin\php.exe, the php.exe then goes through the source file and uses the enviroment variables that the web server posts information to (QUERY_STRING, PATH_INFO) etc and the php.exe outputs the results via STDout

Posted: Wed Feb 28, 2007 5:17 pm
by Jordi
I continue with my tests... I'm not lucky.

Trying to use Paul library I get the same error with the samples on Help. If I leave the file as .exe then it doesn't run but if I change the name to .cgi then it shows the error.

Any idea Paul?

Now time to ask again to hosting company.

Thanks to everyone.

Posted: Wed Feb 28, 2007 5:32 pm
by Paul
Just some things to look for...

When you compiled your EXE, did you set the Executable Format in PB Compiler Options to "Console" ?

Did you place the EXE in the cgi-bin folder on your server?

Are you calling the EXE properly from your web page?


Here is a sample you can download and try:
http://www.gokenora.com/temp/cgitest.exe

Place this "cgitest.exe" file in you cgi-bin folder.
If you have the server running on your local machine for testing, open you browser and type: http://localhost/cgi-bin/cgitest

You should get a "Hello World" in you browser.