【perl】simpleHTTP
发布时间:2020-12-15 23:27:01 所属栏目:大数据 来源:网络整理
导读:类似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:: C
类似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 OKrn"; print $cgi->header( -type => ‘application/json‘,-status => ‘200‘, ); $handler->($cgi); } sub resp_info { my $cgi = shift; # CGI.pm object return 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"; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |