【发布时间】:2011-01-27 10:37:14
【问题描述】:
我在 Windows XP 和 ActiveState ActivePerl 5.8 上有以下代码。
它可能有什么问题?为什么它不起作用?
我尝试将其设置为我的 IE 的代理,但是当我从我的 IE 连接到某些 URL 时,没有任何反应。代码进入线程函数,没有任何反应。
use HTTP::Daemon;
use threads;
use HTTP::Status;
use LWP::UserAgent;
my $webServer;
my $d = HTTP::Daemon->new(
LocalAddr => '127.0.0.1',
LocalPort => 80,
Listen => 20
) || die;
print "Web Server started!\n";
print "Server Address: ", $d->sockhost(), "\n";
print "Server Port: ", $d->sockport(), "\n";
while (my $c = $d->accept) {
threads->create(\&process_one_req, $c)->detach();
}
sub process_one_req {
STDOUT->autoflush(1);
my $c = shift;
while (my $r = $c->get_request) {
if ($r->method eq "GET") {
print "Session info\n", $r->header('Host');
my $ua = LWP::UserAgent->new;
my $response = $ua->request($r);
$c->send_response($response);
} else {
$c->send_error(RC_FORBIDDEN);
}
}
$c->close;
undef($c);
}
【问题讨论】: