如何从Perl Dancer CGI中的flex应用程序中读取URL参数?

时间:2012-11-29 07:13:33

标签: perl cgi dancer

我想知道如何将输入参数传递给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"; 

1 个答案:

答案 0 :(得分:1)

客户端(Flex)无关紧要。查询字符串是查询字符串,发布数据是发布数据,无论将其发送到服务器。

如果您使用的是Dancer,那么您正在使用Plack。如果涉及CGI,则Plack会处理它并将所有环境变量转换为Dancer将使用的标准Plack接口。

您无法直接访问CGI环境变量(也不能访问CGI.pm)。

来自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
    # ...
};

因此:

my $params = request->params;
my $name = $params->{'name'};
my $loc = $params->{'loc'};
相关问题