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; }