perl发送post数据

把post数据写进一个匿名数组里就行

1 #!/usr/bin/env perl -w
2 use strict;
3 use LWP::UserAgent;
4 
5 my $ua = LWP::UserAgent->new();
6 my $rp = $ua->post('http://www.baidu.com', ['username' => 'admin','passwd' => 'password'])
7 print $rp->content();

 或

1 use LWP::UserAgent;
2 my $ua = LWP::UserAgent->new();
3 
4 my $rep = $ua->post('http://localhost/1.php', {cmd => 'whoami'});
5 #my $rep = $ua->post('http://localhost/1.php', ['cmd' => 'whoami']);
6 print $rep->content;

1 use LWP::UserAgent;
2 my $ua = LWP::UserAgent->new();
3 my $req = HTTP::Request->new(POST => 'http://localhost/1.php');
4 $req->content('cmd=whoami');
5 $req->content_type('application/x-www-form-urlencoded');
6 my $rp = $ua->request($req);
7 print $rp->content;

 

如果用最后一个方法, 记得要带有content_type头才行

 

posted on 2017-02-26 22:25  Perl6  阅读(1219)  评论(0编辑  收藏  举报

导航