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\

相关推荐
ControlRookie15 小时前
第13篇_Client 02|TCP 连接成功,为什么 HTTP 请求还没有成功
http·codesys·plc通信·controlrookie
IPdodo跨境网络2 天前
HTTP 与 SOCKS5 代理到底差在哪?用 Node.js 跑一次连接链路对比
http
小小龙学IT2 天前
gRPC 开源高性能 RPC 框架深度解析:从 HTTP/2 到跨语言微服务实战
http·rpc·开源
Misnearch3 天前
MCP以及底层协议、传输模式
http·mcp·json-rpc
Aision_4 天前
实习学习笔记:HTTP请求走私漏洞全方位解析
笔记·学习·安全·web安全·http·网络安全·网络攻击模型
zhao3266857514 天前
除了网页浏览,HTTP和HTTPS代理还能干啥?适用场景有哪些
网络协议·http·https
沐苏瑶4 天前
计算机网络核心笔记:打通 TCP/UDP 与 HTTP/HTTPS 底层逻辑(重点下)
笔记·计算机网络·http
NeilYuen4 天前
实现TCP发送HTTP请求
网络协议·tcp/ip·http
wuhuhuan5 天前
Day17:HTTP 接口测试与链式调用 — sendRequest 从入门到实战
网络·网络协议·http
执笔画流年呀5 天前
网络原理(http)(https)
网络·http·https