I am writing a C CGI program
For GET requests, I assume all the information is somehow stored in getenv(). My question is, what does this array look like a most basic CGI request from the webserver. With two prarameters e.g. username= and password=.
For POST request, I am unsure. I’ve read that stuff is handled on standard input. What do these lines that are passed to a CGI program via standard input (from the webserver) look like?
Pointing me to a verbose RFC is unhelpful.
Any book? I am specifically interested in the low-level details of the protocol. I already know how to write CGI apps with helper libs… I just need to know the semantics of those helper libs.
envpis not standard (well, not ISO C or C++ standard anyway, though POSIX may have something for it).However,
envpis pretty much the same format asargvescept it doesn’t have a controllingargcto limit it.Each
envp[x]will be of the form"key=value"where thekeyis the environment variable name and thevalueis its value, surprisingly enough πYou should process the elements sequentially until you get a NULL pointer, something like:
The Wikipedia entry for CGI gives further details, hopefully without swamping you with too much information like a verbose RFC would.
Copying the relevant stuff to make this answer self-contained:
Beyond that level of detail, you’re probably going to have to look into the RFCs, I’m afraid. A search for RFC3875 on Google should locate it.
Specifically, for
POST, the environment variables are included before the first blank line of the request (the one that introduces the message body). They have the form:where the key is case-insensitive and the value follows the colon.