How can I get both the GET and POST request params

2019-08-04 19:00发布

问题:

I'm creating a facebook app with a Perl backend. The problem is that since Facebook sends the request to my web app as a POST request I'm having a problem getting the GET parameters that were also part of the base URL for the application -- in effect I'm only getting the POST params from $CGI->Vars.

回答1:

See CGI/MIXING POST AND URL PARAMETERS.

Short version: use $CGI->param() for post paramenters and $CGI->url_param() for query string parameters.



回答2:

Dump CGI in favour of a better interface. Plack's param method returns GET and POST parameters mixed.

plackup -MPlack::Request -e 'sub {
    my ($env) = @_;
    my $r = Plack::Request->new($env);
    return [200, ["Content-Type" => "text/plain"], [join "\n", $r->param("foo")]];
}'

> lwp-request -m POST -USe 'http://localhost:5000/fnord?foo=bar;baz=quux'
Please enter content (application/x-www-form-urlencoded) to be POSTed:
foo=123;baz=456
␄
POST http://localhost:5000/fnord?foo=bar;baz=quux
User-Agent: lwp-request/6.03 libwww-perl/6.03
Content-Length: 16
Content-Type: application/x-www-form-urlencoded

200 OK
Date: Thu, 27 Oct 2011 21:27:46 GMT
Server: HTTP::Server::PSGI
Content-Length: 7
Content-Type: text/plain
Client-Date: Thu, 27 Oct 2011 21:27:46 GMT
Client-Peer: 127.0.0.1:5000
Client-Response-Num: 1

bar
123


标签: perl post get cgi