2012-11-29 20 views
0

我想知道如何将输入参数传递给perl cgi。我有一个灵活的应用程序,它将采用一个人的名字和一些其他细节,然后我想用这些细节作为输入来调用perl cgi。怎么可能?在url的末尾添加参数例如:http://localhost/cgi-bin/test.pl?name=abc&location=adsas,将参数传递给perl cgi的唯一方法?如何从Perl Dancer CGI中的flex应用程序读取URL参数?

我怎样才能得到传递参数里面的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

客户端(Flex的)是无关紧要的。查询字符串是一个查询字符串,并且发布数据是发布数据,无论发送给服务器的是什么。

如果您正在使用舞者,那么您正在使用Plack。如果涉及CGI,则Plack将负责处理它并将所有环境变量转换为舞者将使用的标准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'}; 
+0

对不起,我听不懂,我真的很新的Perl。你能解释更多吗?我应该得到完整的代码吗? – neha88

+0

这是真正的基本舞者的东西。你真的使用舞者吗? – Quentin

+0

我懂了...反正thanx ... – neha88