返回顶部

收藏

Perl实现HTTP POST请求

更多

perl代码

use HTTP::Request::Common; 
use LWP::UserAgent;
$user_agent = LWP::UserAgent->new;
$request = POST 'http://www.yourserver.com/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; 

标签:Perl,CGI,HTTP

收藏

0人收藏

支持

0

反对

0

发表评论