특정 주소 (포트 번호, 10.xxx : portNumber)에 대한 웹 서버로 펄을 사용하려고합니다. 또한 기본적으로 내 index.html 파일에있는 내용을 보여줍니다. . 그러나 브라우저에서 10.x.x.x : portNumber를 실행할 때 perl은 index.html의 내용을 표시하지 않습니다. 펄에서 파일을 읽으려면 어떻게해야합니까?펄을 index.html 파일에서 읽음
이 코드는 제가이 문제를 해결하기 위해 노력하고 있습니다.
#!/usr/bin/perl
{
package MyWebServer;
use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);
my %dispatch = (
'/' => \&resp_hello,
);
sub handle_request {
my $self = shift;
my $cgi = shift;
my $path = $cgi->path_info();
my $handler = $dispatch{$path};
if (ref($handler) eq "CODE") {
print "HTTP/1.0 200 OK\r\n";
$handler->($cgi);
} else {
print "HTTP/1.0 404 Not found\r\n";
print $cgi->header,
$cgi->start_html('Not found'),
$cgi->h1('Not found'),
$cgi->end_html;
}
}
sub resp_hello {
my $cgi = shift; # CGI.pm object
return if !ref $cgi;
my $who = $cgi->param('name');
print $cgi->header,
$cgi->start_html("Hello"),
$cgi->h1("Hello Perl"),
$cgi->end_html;
}
}
my $pid = MyWebServer->new(XXXX)->background();
print "Use 'kill $pid' to stop server.\n";
고맙습니다.
브라우저를 통해 펄 스크립트를 어떻게 호출하고 있습니까? –