manish.rathi has asked for the wisdom of the Perl Monks concerning the following question:

name : mary jones
email : mjones@jones.com
If the request method is "get" then it wd be formatted as GET /cgi/register.cgi?name=mary+jones&email=mjones%40jones.com HTTP/1.1
Host: localhost

If the request method is POST, the request message wd look like

POST /cgi/register.cgi HTTP/1.1
Host: localhost
Content-length: 67
Content-type: application/x-www-form-urlencoded

name=mary+jones&email=mjones%40jones.com #this is content body

In case of GET, the string attached to request is received by QUERY_STRING, how is that received in case of POST ?
Content-Length is received by CONTENT_LENGTH parameter on the server. Where does the content body go ? does it move to the server with the request ? Does it get stored in stdin on the server and from there it is read in a scalar variable ?

I am kind of confused with this. I did some reading, but still confused. Pls explain this.

Replies are listed 'Best First'.
Re: get and post request methods
by ikegami (Patriarch) on Mar 07, 2009 at 00:24 UTC

    If you tack on a GET-style query to a POST, it will be accessible via ->url_param() rather than ->param(). This is the case for both CGI and CGI::Simple.

    Update: I misunderstood your question. The answer is: use CGI or CGI::Simple. Whether POST or GET, the parameters will be available using ->param().

      CGI::Simple also has parse_query_string() for this purpose — i.e. after having called it, GET-style parameters will also be accessible via the normal ->param(), with a POST request.

Re: get and post request methods
by mr_mischief (Monsignor) on Mar 06, 2009 at 22:40 UTC
    If you really want to know this stuff, you want to look at the RFCs for the HTTP protocol. If you just want to write code that gets these values on the server properly, just use CGI which already takes care of these things. There are other modules that do such, too.
Re: get and post request methods
by shmem (Chancellor) on Mar 07, 2009 at 02:01 UTC

    In case of GET, the parameters and their values are passed as environment variables to the CGI program in charge. In case of post, the parameters and values (i.e. the content body) are passed into the CGI program in charge via file handle 0 (STDIN). It can be retrieved with the standard mechanisms to read from STDIN:

    my $content_body = do { local $/; <> };

    But you shouldn't do that yourself. The perl core module CGI handles that for you.