zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    世界上最帅的人是谁?
    Java 常量池存放的是什么
    刚 安装 Oracle时,登录会出现的问题, ora-28000: the account is locked
    使用MyBatis Generator自动创建代码
    1.2---翻转字符串(CC150)
    1.1---判断字符串是否所有字符都不相同(CC150)
    1.8---字符串是否是旋转而成(CC150)
    1.7---将矩阵元素为0的行列清零0(CC150)
    String和StringBuffer的转换
    Linux下端口被占用解决
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351113.html
Copyright © 2011-2022 走看看