我正在尝试让一个预先存在的 PERL Web 应用程序在我的本地 MAMP apache2 服务器上运行,并且在获取发布数据时遇到问题。该应用程序使用 cgi.pm 尝试从中获取数据$cgi->param
,但即使以格式发送x-www-form-urlencoded
格式正确的帖子数据,参数也始终为空。
此外,STDIN
如果不以 \* 开头,则始终为空并引发错误。
你好世界form.cgi:
#!/[localpath]/perl5/perlbrew/perls/perl-5.24.0/bin/perl -d
use strict;
use warnings;
print "Content-type: text/html\n\n";
print qq(
<!doctype html>
<html>
<body>
<form action=\"hello-world.cgi\" method=\"POST\">
<input type=\"text\" name=\"myparam\" />
<input type=\"submit\" value=\"submit post var\" />
</form>
</body>
</html>
);
你好世界.cgi:
#!/[localpath]/perlbrew/perls/perl-5.24.0/bin/perl -d
use strict;
use warnings;
use CGI;
my $q = CGI->new();
print "Content-type: text/html\n\n";
print "<p>key = " . $q->param('myparam') . "</p>\n"; #this is always empty
my @names = $q->param;
foreach my $name (@names) {
print "<p>$name = " . $q->param($name) . "</p>"; #this never runs
}
my $postdata = '';
my $in = \*STDIN;
my $bytes = read($in, $postdata, $ENV{'CONTENT_LENGTH'});
print "<p>postdata = $postdata</p>\n"; # postdata is empty
print "<p>content length = " . $ENV{'CONTENT_LENGTH'} . "</p>\n"; # this number seems correct
foreach my $key (keys %ENV) {
print "<p>$key --> $ENV{$key}</p>\n"; # nothing special here
}
httpd.conf:
...
LoadModule cgi_module modules/mod_cgi.so
LoadModule perl_module modules/mod_perl.so
...
ScriptAlias /cgi-bin/ "/[siteroot]/cgi-bin/"
Alias /perl/ "/Applications/MAMP/cgi-bin/"
<IfModule perl_module>
PerlModule ModPerl::Registry
<Location /perl>
SetHandler perl-script
PerlResponseHandler ModPerl::Registry
PerlOptions +ParseHeaders
Options +ExecCGI
</Location>
</IfModule>
我正在使用这些模块通过 perlbrew 运行 PERL v5.24.0:
> perlbrew list-modules
CGI
Date::Parse
Encode::Locale
HTML::Parser
HTML::Tagset
HTTP::Date
HTTP::Message
IO::HTML
LWP::MediaTypes
Perl
Sub::Uplevel
Test::Deep
Test::Needs
Test::NoWarnings
Test::Warn
Try::Tiny
URI
有任何想法吗?