• 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

    1. D:\perl\HTTP-Server-Simple-0.52>gmake install
    2. cp lib/HTTP/Server/Simple/CGI/Environment.pm blib\lib\HTTP\Server\Simple\CGI\Environment.pm
    3. cp lib/HTTP/Server/Simple.pm blib\lib\HTTP\Server\Simple.pm
    4. cp lib/HTTP/Server/Simple/CGI.pm blib\lib\HTTP\Server\Simple\CGI.pm
    5. Installing D:\Strawberry\perl\site\lib\HTTP\Server\Simple.pm
    6. Installing D:\Strawberry\perl\site\lib\HTTP\Server\Simple\CGI.pm
    7. Installing D:\Strawberry\perl\site\lib\HTTP\Server\Simple\CGI\Environment.pm
    8. Appending installation info to D:\Strawberry\perl\lib/perllocal.pod

    官网样例:HTTP::Server::Simple - Lightweight HTTP server - metacpan.org

    1. #!/usr/bin/perl
    2. {
    3. package MyWebServer;
    4. use HTTP::Server::Simple::CGI;
    5. use base qw(HTTP::Server::Simple::CGI);
    6. my %dispatch = (
    7. '/hello' => \&resp_hello,
    8. # ...
    9. );
    10. sub handle_request {
    11. my $self = shift;
    12. my $cgi = shift;
    13. my $path = $cgi->path_info();
    14. my $handler = $dispatch{$path};
    15. if (ref($handler) eq "CODE") {
    16. print "HTTP/1.0 200 OK\r\n";
    17. $handler->($cgi);
    18. } else {
    19. print "HTTP/1.0 404 Not found\r\n";
    20. print $cgi->header,
    21. $cgi->start_html('Not found'),
    22. $cgi->h1('Not found'),
    23. $cgi->end_html;
    24. }
    25. }
    26. sub resp_hello {
    27. my $cgi = shift; # CGI.pm object
    28. return if !ref $cgi;
    29. my $who = $cgi->param('name');
    30. print $cgi->header,
    31. $cgi->start_html("Hello"),
    32. $cgi->h1("Hello $who!"),
    33. $cgi->end_html;
    34. }
    35. }
    36. # start the server on port 8080
    37. my $pid = MyWebServer->new(8080)->background();
    38. 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\

  • 相关阅读:
    2022年朝阳区科技创新课之“产品创新与成果转化”训练营活动圆满结束
    Centos7 离线安装docker
    tcpreplay发包机部署流程
    C++入门学习(1)命名空间和输入输出
    使用MybatisPlus快速进行增删改查
    CenterNet复现
    java运算符
    技术干货|你需要知道的 10 种常见机器学习算法
    网上最全的套接字socket
    解读2022年度敏捷教练行业现状报告
  • 原文地址:https://blog.csdn.net/belldeep/article/details/139551144