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 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. 基于CppHttpLib的Httpserver

    2024-06-09 07:32:02       19 阅读
  2. 轻量级 HTTP 请求组件

    2024-06-09 07:32:02       32 阅读
  3. OpenHarmony轻量级驱动开发

    2024-06-09 07:32:02       27 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-09 07:32:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-09 07:32:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-09 07:32:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-09 07:32:02       18 阅读

热门阅读

  1. 面试 Redis 八股文十问十答第二期

    2024-06-09 07:32:02       12 阅读
  2. ASP.NET Core 中使用基本消息的 RabbitMQ 消费者

    2024-06-09 07:32:02       6 阅读
  3. 第十一章:净世山的考验

    2024-06-09 07:32:02       7 阅读
  4. 力扣每日一题 6/8

    2024-06-09 07:32:02       7 阅读
  5. web前端 麦子学院:探索前端技术的无尽奥秘

    2024-06-09 07:32:02       9 阅读
  6. conda env list,列出来的环境怎么删除掉

    2024-06-09 07:32:02       9 阅读
  7. 阿里云 动态ddns

    2024-06-09 07:32:02       6 阅读
  8. MySQL Show命令集

    2024-06-09 07:32:02       8 阅读