FCGI&x2B;Perl+;lighttpd:POST请求为空

FCGI&x2B;Perl+;lighttpd:POST请求为空,perl,post,request,lighttpd,fastcgi,Perl,Post,Request,Lighttpd,Fastcgi,我在perl上使用了带有fastcgi的lighttpd服务器。 Lighttpd配置: server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", "mod_rewrite", "mod_accesslog", ) server.document-root = "/var/www" ser

我在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",
        ))
)
dispatch.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});
        }
    }
}
这是我的脚本(编辑后):

发送请求:

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参数(二进制POST数据)

你能帮我吗?也许我用错误的方法获取post参数

非常感谢

打开
说明 以下是第一个脚本无法运行的原因:

open FH, "<payload.body";
#         ^---
让Perl来帮助您 事实上,您试图将打印到只读的文件句柄。然而,Perl可以警告您这一点以及您可能遇到的许多其他问题。只需
在脚本顶部使用strict
使用warnings
(实际上是所有脚本)。您可以使用
Carp
模块发出更好的错误消息。请注意,在服务器上,这些警告通常会写入日志,但您在日志中找到的内容值得查找

什么是
Dumper
Data::Dumper
模块采用Perl数据结构,并将其转换为可执行的Perl代码。这对于调试来说非常好,对于序列化来说有时还可以,但是仅仅打印一个字符串或标量是不好的。所有包含的数据都将被引用,以便成为有效的Perl,这不是您想要的

其他零碎
read
从一开始就开始填充目标变量(索引0)。指定偏移量作为第四个参数(例如,
-1
)以附加正在读取的数据

不带第二个参数的
binmode
仅在Windows上有用。 在Windows上,
\n
可以是逻辑换行符(例如“
\r\n
”)。在网络中使用字节值
\015\012

在第二个示例中,使用
STDIN
中的
$ENV{CONTENT\u LENGTH}
字符覆盖
$buffer
。出于调试目的,您可能还需要打印此内容长度


FCGI::Request()
返回请求对象。您必须
接受每个请求的状态,可能在循环中。
Accept
方法在成功的情况下返回一个值
>=0

您可以共享输出的完整转储吗?它不能仅是$VAR1=''我从第一个脚本添加的转储:只有空字符串和标题谢谢。我修正了打字错误,并相应地编辑了我的问题。但输出仍然是空的:(我还没有更正第二个脚本。
open FH, "<payload.body";
#         ^---
open my $fh, '>', "payload.body" or die "Can't open payload.body: $!";