How can I get both the GET and POST request params, on a POST request?

筅森魡賤 提交于 2019-12-11 12:23:38

问题


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


来源:https://stackoverflow.com/questions/7920076/how-can-i-get-both-the-get-and-post-request-params-on-a-post-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!