我在Ubuntu 16.04.1 LTS上使用Apache和mod_perl的默认安装,我也用默认的JSON :: XS转载了这个,我更新到了最新的CPAN JSON-XS-3.02。mod_perl下的JSON :: XS失败,POST请求
下面的代码适用于所有情况下,如果我不使用mod_perl。
下面的脚本和html通过mod_cgi同时使用POST和GET请求来使用perl时工作。
如果不过我使用的是mod_perl并且使用POST(如在提供的html中),它会失败,“Hello”不会打印,并且在我的apache日志文件中出现以下错误。
用法:JSON :: XS :: new(klass)。
如果我通过GET方法传递相同的参数,那么脚本工作正常。
test2.pl
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use JSON::XS;
my $q = new CGI();
print $q->header(-type => 'text/plain');
my $action = $q->param('a');
my $json_str = '{"foo":"bar"}';
my $pscalar = JSON::XS->new->utf8->decode($json_str);
print "Hello";
exit 1;
HTML调用以上(在服务器上名为test2.pl)
<html>
<body>
<form action="test2.pl" method="POST">
<input type="text" name="a"/>
<button type="submit">
</form>
</body>
</html>
没有,做同样的事情。 – Severun