【perl】simpleHTTP
生活随笔
收集整理的這篇文章主要介紹了
【perl】simpleHTTP
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
【perl】simpleHTTP
類似Python SimpleHTTPServer
#!/usr/bin/perl # https://metacpan.org/pod/HTTP::Server::Simple # https://metacpan.org/pod/distribution/CGI/lib/CGI.pod package WebServer;use strict; use warnings FATAL => 'all'; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); use JSON;sub handle_request {my $self = shift;my $cgi = shift;my $handler = \&resp_info;print "HTTP/1.0 200 OK\r\n";print $cgi->header(-type => 'application/json',-status => '200',);$handler->($cgi); }sub resp_info {my $cgi = shift; # CGI.pm objectreturn if !ref $cgi;# my $who = $cgi->param('name');my %rec_hash = ('path' => $cgi->path_info(),'method' => $cgi->request_method());my $json = encode_json \%rec_hash;print $cgi->param(-name => 'data',-value => $json,); };# start the server on port 8080 my $pid = WebServer->new(8080)->run(); # my $pid = WebServer->new(8080)->background(); # print "Use 'kill $pid' to stop server.\n";?
posted on 2019-04-23 11:12 poorX 閱讀(...) 評論(...) 編輯 收藏轉載于:https://www.cnblogs.com/jiangxu67/p/10755247.html
總結
以上是生活随笔為你收集整理的【perl】simpleHTTP的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 台电固态硬盘用什么测试软件,常规测试、实
- 下一篇: 2019 wannafly winter