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\

相关推荐
lay_liu5 小时前
报错The default superclass, “jakarta.servlet.http.HttpServlet“(已经配置好tomcat)
http·servlet·tomcat
蓝色心灵-海6 小时前
小律书 技术架构详解:前后端分离的自律管理系统设计
java·http·小程序·架构·uni-app
cyforkk7 小时前
细节决定架构的成败:API 限流与 HTTP 429 状态码的优雅落地
网络协议·http·架构
Byte不洛8 小时前
基于 C++ 手写 HTTP 服务器:从请求解析到响应构建全流程解析
linux·网络·c++·计算机网络·http
ZTLJQ8 小时前
网络通信的基石:Python HTTP请求库完全解析
开发语言·python·http
无籽西瓜a8 小时前
WebSocket详解含图解:协议特性、握手流程
网络·后端·websocket·网络协议·http
小王不爱笑1328 小时前
HTTP 与 HTTPS
网络协议·http·https
夜泉_ly8 小时前
泉面 TOP150 -HTTP和HTTPS协议的区别?
网络协议·http·https
钛态21 小时前
Flutter 三方库 http_mock_adapter — 赋能鸿蒙应用开发的高效率网络接口 Mock 与自动化测试注入引擎(适配鸿蒙 HarmonyOS Next ohos)
android·网络协议·flutter·http·华为·中间件·harmonyos
2301_805962931 天前
ESP32远程OTA升级:从局域网到公网部署
网络·后端·http·esp32