1

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.

qodeninja
  • 10,946
  • 30
  • 98
  • 152

3 Answers3

13

See CGI/MIXING POST AND URL PARAMETERS.

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

Ven'Tatsu
  • 3,565
  • 16
  • 18
  • well the problem is that the URL is using get parameters to keep track of the application state, I guess the idea is to not mix get and post params -- other than it being part of the RFC standard I dont understand why this matters -- its not changing anything on the server, its just detecting which step to do – qodeninja Oct 27 '11 at 18:49
  • 2
    @nodebunny, Why what matters? Do you mean "why are they fetched using different methods"? To ensure that "Under no circumstances will the contents of the URL query string interfere with similarly-named CGI parameters in POSTed forms." This feature should be especially important to you according to what you said. – ikegami Oct 27 '11 at 20:46
  • why it matters to keep GET and POST separated... but I think I understand the implications. You dont want to be able to set something as a GET param and it be treated a POST param, otherwise that defeats the purpose of having POST, right? However for my purposes I'm only looking for specific params so I guess its a mute point. The params I need whether its get or post doesnt matter. But I understand the situation better now. +1 for discussion – qodeninja Oct 27 '11 at 20:54
5

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
daxim
  • 39,270
  • 4
  • 65
  • 132
0

Just set $CGI::APPEND_QUERY_STRING = 1;

DomQ
  • 4,184
  • 38
  • 37