当前位置: 首页 > news >正文

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 objectreturn 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\

http://www.lryc.cn/news/369727.html

相关文章:

  • 【STM32】基于I2C协议的OLED显示(利用U82G库)
  • 掌握Python3输入输出:轻松实现用户交互、日志记录与数据处理
  • 用于每个平台的最佳WordPress LMS主题
  • pytorch 加权CE_loss实现(语义分割中的类不平衡使用)
  • 【iOS】UI——关于UIAlertController类(警告对话框)
  • django支持https
  • 算法题day41(补5.27日卡:动态规划01)
  • 【附带源码】机械臂MoveIt2极简教程(四)、第一个入门demo
  • 基于蚁群算法的二维路径规划算法(matlab)
  • 政务云参考技术架构
  • android 13 aosp 预置so库
  • mongo篇---mongoDB Compass连接数据库
  • 基于SOA海鸥优化算法的三维曲面最高点搜索matlab仿真
  • 前端js解析websocket推送的gzip压缩json的Blob数据
  • 【wiki知识库】06.文档管理接口的实现--SpringBoot后端部分
  • c,c++,go语言字符串的演进
  • vue-cli 快速入门
  • 机器人--矩阵运算
  • 期末复习【汇总】
  • 【IM即时通讯】MQTT协议的详解(3)- CONNACK Packet
  • Linux - 深入理解/proc虚拟文件系统:从基础到高级
  • Django DeleteView视图
  • 代码杂谈 之 pyspark如何做相似度计算
  • 混剪素材哪里找?分享8个热门素材网站
  • 临床应用的深度学习在视网膜疾病的诊断和转诊中的应用| 文献速递-视觉通用模型与疾病诊断
  • 中继器简介
  • websocket 前端项目js示例
  • webapi跨越问题
  • 你知道 npmrc 文档吗? ---- npmrc 关键作用介绍
  • 发现 Laravel 中的 api 响应时间明显过长