欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > perl use HTTP::Server::Simple 轻量级 http server

perl use HTTP::Server::Simple 轻量级 http server

2024/11/29 23:28:16 来源:https://blog.csdn.net/belldeep/article/details/139551144  浏览:    关键词:perl use HTTP::Server::Simple 轻量级 http server

cpan -i  HTTP::Server::Simple

返回:已是 up to date. 但是我在 D:\Strawberry\perl\site\lib\ 找不到 HTTP\Server

手工安装:下载 HTTP-Server-Simple-0.52.tar.gz

解压 tar zxvf HTTP-Server-Simple-0.52.tar.gz 

cd D:\perl\HTTP-Server-Simple-0.52

perl Makefile.PL

gmake install

D:\perl\HTTP-Server-Simple-0.52>gmake install
cp lib/HTTP/Server/Simple/CGI/Environment.pm blib\lib\HTTP\Server\Simple\CGI\Environment.pm
cp lib/HTTP/Server/Simple.pm blib\lib\HTTP\Server\Simple.pm
cp lib/HTTP/Server/Simple/CGI.pm blib\lib\HTTP\Server\Simple\CGI.pm
Installing D:\Strawberry\perl\site\lib\HTTP\Server\Simple.pm
Installing D:\Strawberry\perl\site\lib\HTTP\Server\Simple\CGI.pm
Installing D:\Strawberry\perl\site\lib\HTTP\Server\Simple\CGI\Environment.pm
Appending installation info to D:\Strawberry\perl\lib/perllocal.pod

官网样例:HTTP::Server::Simple - Lightweight HTTP server - metacpan.org

#!/usr/bin/perl
{
package MyWebServer;use HTTP::Server::Simple::CGI;
use base qw(HTTP::Server::Simple::CGI);my %dispatch = ('/hello' => \&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 objectreturn if !ref $cgi;my $who = $cgi->param('name');print $cgi->header,$cgi->start_html("Hello"),$cgi->h1("Hello $who!"),$cgi->end_html;
}} # start the server on port 8080
my $pid = MyWebServer->new(8080)->background();
print "Use 'kill $pid' to stop server.\n";

运行 perl http_server.pl

浏览器访问 http://localhost:8080/hello?name=Alien
鼠标右键,查看网页源代码。

最后我找到了 cpan 安装所在位置 D:\Strawberry\perl\vendor\lib\HTTP\Server\

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com