perl 获取post响应信息

[root@dr-mysql01 ~]# cat zabbix.pl 
use  LWP::UserAgent;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::Ping;  
use Socket;
use Net::SMTP;
use LWP;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use URI::Escape;
use URI::URL;
my $ua = LWP::UserAgent->new;
$ua->timeout(5);
$ua->env_proxy;
$ua->agent("Mozilla/8.0");
  my $cookie_jar = HTTP::Cookies->new(
      file=>'lwp_cookies.txt',
      autosave=>1,
      ignore_discard=>1);
      $ua->cookie_jar($cookie_jar);

 my $login_url = 'http://192.168.32.83/zabbix/index.php';
                
      my $res = $ua->post($login_url,
                                 {
                         'name'=>admin,
                         'password'=>zabbix,
                         'autologin'=>1,
                         'enter'=>'Sign in'
                                                }
);
     my $homepage; 
                                                                                                                                                                                                 print "---------------
";
print $res->header('Location');

$page= $ua->get('http://192.168.32.83/zabbix/discovery.php');
#print $page->decoded_content;  

 my $login_url = 'http://192.168.32.83/api_jsonrpc.php';

      my $res = $ua->post($login_url,
    {"jsonrpc"=> "2.0",
    "method"=> "host.create",
    "params"=> {
        "host"=> "a123",
        "interfaces"=> [
            {
                "type"=> 1,
                "main"=> 1,
                "useip"=> 1,
                "ip"=> "192.168.3.1",
                "dns"=> "",
                "port"=> "10050"
            }
        ],
        "groups"=> [
            {
                "groupid"=> "11"
            }
        ],
        "templates"=> [
            {
                "templateid"=> "20045"
            }
        ],
        "inventory"=> {
            "macaddress_a"=> "01234",
            "macaddress_b"=> "56768"
        }
    },
    "auth"=> "038e1d7b1735c6a5436ee9eae095879e",
    "id"=> 1
}
                                 
);
print $res->header('Location');
print $res->{_content};


[root@dr-mysql01 ~]# perl zabbix.pl 
---------------
discovery.php<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api_jsonrpc.php was not found on this server.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at 192.168.32.83 Port 80</address>
</body></html>

原文地址:https://www.cnblogs.com/hzcya1995/p/13351113.html