perl中调用cgi

来源:

http://www.cnblogs.com/itech/archive/2012/09/23/2698856.html

参考:
http://www.willmaster.com/library/manage-forms/using_perl_to_submit_a_form.php

http://www.oschina.net/code/snippet_12_854

有时需要在perl中非交互地调用已有的cgi来完成一定的功能,此时需要模拟一个http请求来调用cgi。

get方式调用:

       use HTTP::Request::Common;
use LWP::UserAgent;
$user_agent = LWP::UserAgent->new;
$request = GET 'http://clearcase/~xhzhu/cgi/cgireader.cgi?text1=hello&text2=here';
$response = $user_agent->request($request);
print $response->as_string;

post方式调用:

 use HTTP::Request::Common;
use LWP::UserAgent;
$user_agent = LWP::UserAgent->new;
$request = POST 'http://clearcase/~xhzhu/cgi/cgireader.cgi',
[text1 => 'Hello', text2 => 'there'];
$response = $user_agent->request($request);
print $response->as_string;

cgireader.cgi:

 #!/usr/local/bin/perl
use CGI;
$co = new CGI;
print $co->header,
$co->start_html(
-title=>'CGI Example',
-author=>'yourName',
-BGCOLOR=>'white',
-LINK=>'red'
);
if ($co->param()) {
print
"You entered this text: ",
$co->em($co->param('text1')),
" ",
$co->em($co->param('text2')),
".";
} else {
print "Sorry, I did not see any text.";
}
print $co->end_html;
上一篇:什么是Service Mesh?


下一篇:开课吧百万年薪架构师一期(智能互联网之容器弹性云与Service Mesh)