• 阿里云 测试调用接口


    use  LWP::UserAgent;
    use Data::UUID;
    use Data::GUID;
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);  
    use HTTP::Cookies;
    use POSIX;
    my $uuid  = Data::GUID->new->as_string;
    print "$uuid is $uuid
    ";
    
    use Encode;
    
    my $SDATE = strftime("%Y-%m-%dT%H:%M:%SZ",localtime());
    use URI::Escape;  
    $SDATE=uri_escape("$SDATE"); 
    print "$SDATE is $SDATE
    X";
    $SDATEX = $SDATE;
    $SDATEX =~ s#%#%25#g;
    print "$SDATEX is $SDATEX
    ";
    
    
    use URI::Escape qw(uri_unescape);
    use MIME::Base64;
    use Digest::HMAC_SHA1;
    $xx="GET&%2F&AccessKeyId%3DZ7MNVh%26Action%3DDescribeRegions%26Format%3DJSON%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3D$uuid%26SignatureVersion%3D1.0%26TimeStamp%3D$SDATEX%26Version%3D2014-05-26";
    $xx = encode_utf8($xx);
    print "$xx is $xx
    ";
    $str=Digest::HMAC_SHA1::hmac_sha1("$xx","fQIJLxzkj&");
    $Signature = encode_base64($str,"");
    print "$Signature
    ";
     $Signature = encode_utf8($Signature);
     
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $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);
    
    $head='http://ecs.aliyuncs.com/?';
    #+ 替换为%20 =替换为%3d
    $Signature = uri_escape("$Signature");
    
    
    
    $api="SignatureVersion=1.0&Format=JSON&TimeStamp=$SDATE&RegionId=region1&AccessKeyId=Z7bpNVh&SignatureMethod=HMAC-SHA1&Version=2014-05-26&Signature=$Signature&Action=DescribeRegions&SignatureNonce=$uuid";
    $url=$head.$api;
    print "$url is $url
    ";
    my $response = $ua->get($url);
    
    
    if ($response->is_success) {
    $yy=$response->decoded_content;
    my $var=encode("gbk",decode("utf8",$yy));
     print $var;  # or whatever
     }
     else {
      print $response->decoded_content;  # or whatever
       die $response->status_line;
       }

  • 相关阅读:
    获取数据窗口的report对象 pb
    职业中的人与人。。。
    关于表格的设置
    今天学到的关于UI的一点东西
    给QQ发匿名消息
    这两天在改以前写的程序,很闷,记点流水账,:)
    我也要回家了,给大家道别
    时间过的好快啊,2月1号了,几个问题!
    开始新的一年的新生活..
    @dudu,临走问一下
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351007.html
Copyright © 2020-2023  润新知