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 小时前
基于C语言 HTTP 服务器客户端的实验
服务器·c语言·http
打不了嗝 ᥬ᭄4 小时前
【Linux】网络层协议
linux·网络·c++·网络协议·http
一叶飘零_sweeeet4 小时前
Java 项目 HTTP+WebSocket 统一权限控制实战
java·websocket·http·权限控制
进击的圆儿4 小时前
HTTP协议深度解析:从基础到性能优化
网络协议·http·性能优化
周杰伦fans16 小时前
.NET Core WebAPI 中 HTTP 请求方法详解:从新手到精通
网络协议·http·.netcore
@大嘴巴子20 小时前
零基础学习计算机网络编程----理解http协议
学习·计算机网络·http
利刃大大21 小时前
【高并发服务器:HTTP应用】十五、HttpRequest请求模块 && HttpResponse响应模块设计
服务器·c++·http·项目
自由生长20241 天前
HTTP2的介绍:从独木舟运货”到“细沙流淌”
http
一直向钱1 天前
基于你的 SRS 直播流煤体配置(通过 http_hooks 回调实现鉴权),结合 TP6 框架,以下是完整的 PHP SDK 封装方案
网络协议·http·php
爱编程的鱼1 天前
301 是什么意思?——HTTP 状态码详解与应用
网络·网络协议·http