Seitenanfang

Parse both GET and POST data in the same request using CGI::Simple

Dieser Post wurde aus meiner alten WordPress-Installation importiert. Sollte es Darstellungsprobleme, falsche Links oder fehlende Bilder geben, bitte einfach hier einen Kommentar hinterlassen. Danke.


The Perl CGI module is commonly used, but it's heavy. CGI::Simple is more lightweight but lacks some features. Here is a feature not supported by CGI but by CGI::Simple.

Both modules are really simple to use: Create a new object using one of them and all GET or POST data will be parsed in most environments. I was fighting with the Facebook registration API and finally discovered that you can't pass any fixed/hidden variables from the form to the script (any longer. I'm pretty sure that this was working during my first tests some time ago).

Passing my hidden fields as additional GET arguments to the target URL worked... until they hit CGI::Simple and it's parser. All GET arguments are completly ignored on a POST request! Common, and maybe also part of the HTTP RFC but all my selfmade parser modules combined both arguments.

I was looking for a good & clean solution doing as few of CGI::Simple's work manually as possible - and found a solution! Hidden somewhere in the huge documentation of the module:

parse_query_string() Add QUERY_STRING data to 'POST' requests

When the REQUEST_METHOD is 'POST' the default behavior is to ignore name/value pairs or keywords in the $ENV{'QUERY_STRING'}. You can override this by calling parse_query_string() which will add the QUERY_STRING data to the data already in our CGI::Simple object if the REQUEST_METHOD was 'POST'

Few lines of documentation but exactly what I need.

I think, I'll add it as default after every CGI::Simple->new call from now on (as long as POST or GET data is treated the same within the script, but I won't trust the METHOD for security checks anyway).

 

Noch keine Kommentare. Schreib was dazu

Schreib was dazu

Die folgenden HTML-Tags sind erlaubt:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>