0

我想知道如何将输入参数传递给 perl cgi 。我有一个 flex 应用程序,它将获取一个人的姓名和其他一些详细信息,然后我想调用一个 perl cgi,并将这些详细信息作为输入。怎么可能?是否在 url 末尾附加参数,例如:http://localhost/cgi-bin/test.pl?name=abc&location=adsas,将参数传递给 perl cgi 的唯一方法?

如何在 perl cgi 中获取传递的参数?

我试过这段代码但没有得到输出

use CGI qw(:standard);
use strict;
my $query = new CGI;
my $name = $query->param('name');
my $loc = $query->param('loc');
print "$name is from $loc\n"; 
4

1 回答 1

1

The client (Flex) is irrelevant. A query string is a query string and post data is post data, no matter what sends it to the server.

If you are using Dancer, then you are using Plack. If CGI is involved, then Plack will take care of it and translate all the environment variables to the standard Plack interface which Dancer will consume.

You can't access the CGI environment variables directly (and nor can CGI.pm).

From the docs:

get '/foo' => sub {
    request->params; # request, params parsed as a hash ref
    request->body; # returns the request body, unparsed
    request->path; # the path requested by the client
    # ...
};

Therefore:

my $params = request->params;
my $name = $params->{'name'};
my $loc = $params->{'loc'};
于 2012-11-29T11:20:43.993 回答