【发布时间】:2019-06-12 06:01:38
【问题描述】:
如何找到HTTP::Daemon 模块中的$code 和$mess?在 cpan 中的用法是
$c->send_status_line( $code, $mess, $proto )
但我不知道从哪里/如何获得$code、$mess。
例如,send_error($code) 用作send_error(RC_FORBIDDEN),这是我从网上某人的代码中找到的,他从哪里得到RC_FORBIDDEN?
一直在玩下面的代码。很抱歉格式化,非常感谢@choroba 为我格式化。
use warnings;
use strict;
use HTTP::Daemon;
use HTTP::Status;
use LWP;
my $daemon = HTTP::Daemon->new or die;
my $d = HTTP::Daemon->new(
LocalAddr => '0.0.0.0',
LocalPort => '5000',
);
printf ("\n\n URL of webserver is %s, show this script with %stest\n",
$d->url, $d->url);
while (my $client_connection = $d->accept)
{
new_connection($client_connection);
}
sub new_connection
{
my $client_connection = shift;
printf "new connection\n";
while (my $request = $client_connection->get_request)
{
if (my $pid = fork)
{
print "Child created : $pid\n";
}
elsif (!defined $pid)
{
die "Cannot fork $!\n";
}
else
{
my $address_of_client = $client_connection->peerhost();
my $port_of_client = $client_connection->peerport();
print "Connection from client $address_of_client on port
$port_of_client\n";
print " request\n";
if ($request->method eq 'GET' and $request->uri->path
eq "/test")
{
$client_connection->send_file_response(RC_OK);
#$client_connection->send_status_line(200);
#print "OK ";
#$client_connection->send_file_response($0);
}
else
{
$client_connection->send_error(RC_NOT_FOUND);
}
}
$client_connection->close;
}
}
【问题讨论】:
-
您要发送什么代码和消息?如果你不想发送任何代码和消息,为什么要调用该方法?
标签: perl