我在 perl 上有带有 fastcgi 的 lighttpd 服务器。Lighttpd 配置:
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_rewrite",
"mod_accesslog",
)
server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.max-keep-alive-requests = 10
server.max-keep-alive-idle = 5
#server.max-fds = 10240
server.max-connections = 8192
index-file.names = ( "index.php", "index.html",
"index.htm", "default.htm",
"index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
dir-listing.encoding = "utf-8"
server.dir-listing = "disable"
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
$HTTP["host"] =~ "(^|\.)hostname\.net$" {
server.document-root = "/var/www/hostname.net"
url.rewrite-once = (
"^/index.php" => "/index.pl",
)
}
启用快速 CGI。这里配置fcgi.server:
fastcgi.server += ( ".pl" =>
((
"socket" => "/tmp/perl.socket" + var.PID,
"bin-path" => "/usr/bin/dispatch.fcgi",
"docroot" => "/var/www/hostname.net",
"check-local" => "disable",
))
)
调度.fcgi:
use strict;
use CGI::Fast;
use Embed::Persistent; {
my $p = Embed::Persistent->new();
while (new CGI::Fast) {
my $filename = $ENV{SCRIPT_FILENAME};
my $package = $p->valid_package_name($filename);
my $mtime;
if ($p->cached($filename, $package, \$mtime)) {
eval {$package->handler;};
}
else {
$p->eval_file($ENV{SCRIPT_FILENAME});
}
}
}
这是我的脚本(编辑后):
use strict;
use warnings;
use CGI;
my $q = new CGI;
open my $fh, '>', "/var/www/hostname.net/payload.body" or die "Can't open payload.body: $!";
{
local $/;
print $fh $q->param('arg1');
}
close $fh;
print $q->header;
print $q->param('arg1');
发送请求:
wget --post-data="arg1=dfsdfasf&arg2=sdfasfdsdf" http://hostname.net/test.pl --save-headers --quiet -O -
payload.body 为空(但更改更新时间)并且转储为:
HTTP/1.0 200 OK
Content-Type: text/html; charset=ISO-8859-1
Content-Length: 0
Connection: keep-alive
Date: Fri, 05 Oct 2012 12:23:07 GMT
Server: lighttpd/1.4.28
就这样。
我尝试通过这种方式获取 POST 参数,但查询为空。我这样尝试过:
use Data::Dumper;
my $request;
use FCGI;
my $env;
my $q = FCGI::Request();
$env = $q->GetEnvironment();
my $buffer = "data\n";
if ( $ENV{'REQUEST_METHOD'} eq "POST" ){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}
else {
print ("some error");
};
print("Content-type: text/plain\r\n\r\n", Dumper($buffer),"\n");
我需要从请求(二进制发布数据)中获取 POST 参数。
你能帮助我吗?也许我以错误的方式获取帖子参数?
非常感谢!