CGI on Windows 2003 hosting

Just starting out? Need help? Post your questions and find answers here.
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

CGI on Windows 2003 hosting

Post 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.
Last edited by Jordi on Sun Feb 25, 2007 9:41 pm, edited 1 time in total.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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.
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post 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.
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post 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!
User avatar
yoxola
Enthusiast
Enthusiast
Posts: 386
Joined: Sat Feb 25, 2006 4:23 pm

Post by yoxola »

Windows 20003 :shock:

I'm going to join a time travel...
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post 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.
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post 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
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! ;)"
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post 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...
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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
Image Image
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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 :)
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post 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.
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post 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
Jordi
User
User
Posts: 53
Joined: Sat Apr 26, 2003 10:19 am
Location: Cosmos

Post 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.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1285
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post 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.
Image Image
Post Reply