Apache上的Perl脚本不检索POST数据



我正在尝试在我的本地 MAMP apache2 服务器上运行一个预先存在的 PERL Web 应用程序,但在获取发布数据时遇到问题。该应用程序使用 cgi.pm 尝试从$cgi->param中获取数据,但即使以x-www-form-urlencoded格式发送格式正确的帖子数据,param 也始终为空。

此外,STDIN始终为空,如果未以 \* 开头,则会引发错误。

你好-世界形态.cgi:

#!/[localpath]/perl5/perlbrew/perls/perl-5.24.0/bin/perl -d
use strict;
use warnings;
print "Content-type: text/htmlnn";
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/htmlnn";
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

有什么想法吗?

从 shebang 中删除-d可以解决此问题。感谢科里昂的回答。