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

perl 复制代码
#!/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 object
    return 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\

相关推荐
菜鸟是大神1 天前
【已解决】docker: Error response from daemon: Get “https://registry-1.docker.io/v2/“: net/http: request c
http·docker·容器
Arwen3031 天前
从 “http” 到 “https”:只差一张 SSL
http·https·ssl
handsomestWei2 天前
大华设备netsdk http服务封装
http·netsdk·大华·门禁
hello 早上好2 天前
TCP/IP、SOCKET、HTTP
网络协议·tcp/ip·http
群联云防护小杜2 天前
应用层攻防启示录:HTTP/HTTPS攻击的精准拦截之道
服务器·网络协议·http·https·ddos
Hong.19482 天前
解决http的web服务中与https服务交互的问题
前端·http·https
Arwen3032 天前
常见 SSL 证书问题解答:从报错到维护全涵盖
服务器·网络·网络协议·http·https·ssl·html5
小诸葛的博客2 天前
istio-proxy用哪个端口代理http流量的?
http·云原生·istio
AlfredZhao2 天前
SQLcl:不仅是 SQL*Plus 的继任者,更是 AI 时代的连接器
vscode·server·mcp·cline·sqlcl
阿沁QWQ3 天前
HTTPS 协议原理
网络协议·http·https