perl实例之post cgi参数的例子

发布时间:2019-09-27编辑:脚本学堂
本文分享一例perl代码,实现post传递perl cgi参数的例子,有需要的朋友参考下。

perl cgi编程实例,post方式传递cgi参数。
代码:
 

复制代码 代码示例:
#!/bin/perl
   
use HTTP::Request::Common;
use LWP::UserAgent;
$user_agent = LWP::UserAgent->new;
$request = POST 'http://www.jb200.com/cgireader.cgi',[text1 => 'Hello', text2 => 'there'];
$response = $user_agent->request($request);
print $response->as_string;

2,File: 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;