CGI on Windows 2003 hosting
CGI on Windows 2003 hosting
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.
"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.
Last edited by Jordi on Sun Feb 25, 2007 9:41 pm, edited 1 time in total.
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.
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.
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
Thanks.
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

Thanks.
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!
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!
IIS is very strict regarding header checks:
Try something like:
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
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>'
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
Last edited by Thalius on Fri Feb 23, 2007 10:23 pm, edited 1 time in total.
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone!
"
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone!

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...
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...
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
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
StdOut auto adds the Chr 13 + 10 automatically, this is needed 
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>")

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
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.
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

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.
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
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
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.
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.