in reply to Re^7: How to parse URL in CGI.pm
in thread How to parse URL in CGI.pm

Yes, I figured this out...

Is there a way of getting the message body without using the CGI.pm?

Replies are listed 'Best First'.
Re^9: How to parse URL in CGI.pm
by Corion (Patriarch) on Dec 07, 2010 at 15:36 UTC

    Why are you asking about CGI.pm and then asking about how to do things without using it?

    Just use CGI.pm and be done with it.

    CGI.pm knows about mod_perl.

      He can't, CGI expects a URL encoded form, but he's getting something slightly different. As such, he needs to do his own query parsing.
      The problem is that the query_string in CGI.pm doesn't give my the required string and I need to parse it by myself

      I understood that the way of doing it is to look for the ENV.

      My question is:

      Is there an ENV which gives my the message body in case of a POST request?

      Thanks!

        You should have no problem with CGI for POST unless you're being given garbage (e.g. being told you are provided something's that "application/x-www-form-urlencoded" when it isn't).

        my $url; if ($cgi->request_method eq 'GET') { # Can't use ->param('url') because the client is # providing the parameters in a stupid format. ( $url = $ENV{QUERY_STRING} ) =~ s/^.*[?&]url=//s; } else { $url = $cgi->param('url'); }

        If you are getting garbage, it can be handled. You've been given the link to the CGI spec. Read it. Your asking questions with no apparent effort at answering them yourself.

        Are you sure it's CGI.pm that messes up the query_string, or happens this already at the user agent?
        Is there an ENV which gives my the message body in case of a POST request?
        A few seconds with the CGI.pm manual page reveals:
               If POSTed data is not of type application/x-www-form-urlencoded or
               multipart/form-data, then the POSTed data will not be processed, but
               instead be returned as-is in a parameter named POSTDATA.  To retrieve
               it, use code like this:
        
                  my $data = $query->param('POSTDATA');
        
        You could have found this out for yourself.

        But if it's CGI.pm that is causing you all this grief, consider not using CGI.pm. Using the CGI protocol (which is different from CGI.pm!), you get the POST data on STDIN.