0
我试图通过perl获取d请求。但即时得到以下错误:Perl - 伪哈希已弃用
#!/usr/bin/perl
use lib "/usr/packages/perl/perl-5.16.3/lib/5.16.3";
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use MIME::Base64;
my $url = 'https://example.com:8443/cli/agentCLI';
my $credentials = encode_base64('username:password');
my $ua = LWP::UserAgent->new(ssl_opts =>{ verify_hostname => 0});
my $response = $ua->get($url, 'Authorization' =>" Basic $credentials");
die 'http status: ' . $response->code . ' ' . $response->message
unless ($response->is_success);
my $json_obj = JSON->new->utf8->decode($response->content);
# the number of rows returned will be in the 'rowCount' propery
print $json_obj->{rowCount} . " rows:n";
# and the rows array will be in the 'rows' property.
foreach my $row(@{$json_obj->{rows}}){
#Results from this particular query have a "Key" and a "Value"
print $row->{Key} . ":" . $row->{Value} . "n";
}
输出(误差):
伪散列在agent.pl线弃用21. 没有这样的伪散列字段“rowCount时”在agent.pl线21 。
感谢, Kalaiyarasan
很明显,JSON并不像您期望的那样解码。尝试转储结果(使用Data :: Dumper;打印Dumper($ json_obj);'看看你实际得到了什么 – 2015-03-08 18:30:46
谢谢安德鲁......它的工作很好.. – Kalaiyarasan 2015-03-08 18:33:45
PS,'/ usr/packages/perl/perl-5.16.3/lib/5.16.3'应该是'/ usr/packages/perl/perl-5.16.3/lib'。'use lib $ dir;'会寻找arch subdirs('$ dir/$ archname','$ dir/$ version'和'$ dir/$ version/$ archname')并添加它们。 – ikegami 2015-03-08 23:04:00