lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Aug 5, 2013, at 1:04 PM, Henrique Gogó <> wrote:

> How do I get "GET parameters" and POSTS, or request header using CGI
> scripts…

CGI is very simple… all you need is in the script environment (as per os.getenv).

The URL parameters are in QUERY_STRING.  So os.getenv( 'QUERY_STRING' ). They are URL-encoded, so you need to decode them before using them. See example bellow.  

For a POST, the parameters are in the request body. So you need to get the length of the content (os.getenv( "CONTENT_LENGTH" ) ), then read that much from io.stdin. Again, the parameters will be encoded ( 'application/x-www-form-urlencoded' usually, possibly 'multipart/form-data'). You will need to decode them as well.

Etc, etc, etc...

Here are some details about CGI:

The Common Gateway Interface (CGI) Version 1.1

And a little usage example.

Attachment: CGI.lua
Description: Binary data