[Gambas-user] CGI - Hello World

Benoit Minisini gambas at ...1...
Wed Nov 22 16:37:25 CET 2006


On Wednesday 22 November 2006 15:43, James Linden wrote:
> It just hit me that I don't know how much Gambas is doing internally...
> The first line of this SUB would be required for a conforming HTTP
> response.
>
> PUBLIC SUB Main()
>    PRINT "HTTP/1.1 200 OK\r\n"
>    PRINT "Connection: close\r\n"
>    PRINT "Content-Type: text/html; charset=iso-8859-1\r\n"
>    PRINT "\r\n"
>    PRINT "Hello World!"
> END
>
> For more info, read RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html>.
> Also, try telnet'ing into a valid web server:
>
> telnet gambas.sourceforge.net 80
>
>  > HTTP/1.1 GET / <and hit enter twice>
>
> -- James
>

Actually PRINT prints a new line, so you should do:

File.Out.EndOfLine = gb.Windows ' New lines are '\r\n' and not '\n' now.
PRINT "Content-Type: text/html"
PRINT
PRINT "<html>"
...

By default, Gambas does nothing internally. 

If you use the gb.web component, it will just do 'File.Out.EndOfLine = 
gb.Windows' and 'File.In.EndOfLine = gb.Windows' automatically as soon as a 
CGI environment variable is used by one of the component methods.

Regards,

-- 
Benoit Minisini





More information about the User mailing list