2012-11-29 24 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