After some struggle, I got the first JSON::RPC library at CPAN to work:
Code:
use JSON::RPC::Client;
use Data::Dumper;
my $client = new JSON::RPC::Client;
$client->ua->credentials(
'localhost:8332', 'jsonrpc', 'my rpcusername' => 'my rpcpassword' # Replace with real user/pass
);
my @foo = $client->ua->credentials('localhost:8332', 'jsonrpc');
print "@foo\n";
my $uri = 'http://localhost:8332/';
my $obj = {
method => 'getinfo',
params => [],
};
my $res = $client->call( $uri, $obj );
if($res){
if ($res->is_error) {
print "Error : ", $res->error_message;
}
else {
print Dumper($res->result);
}
}
else {
print $client->status_line;
}
The struggle was setting the realm to 'jsonrpc' (it is fussy about that). I'll document that on the wiki.use Data::Dumper;
my $client = new JSON::RPC::Client;
$client->ua->credentials(
'localhost:8332', 'jsonrpc', 'my rpcusername' => 'my rpcpassword' # Replace with real user/pass
);
my @foo = $client->ua->credentials('localhost:8332', 'jsonrpc');
print "@foo\n";
my $uri = 'http://localhost:8332/';
my $obj = {
method => 'getinfo',
params => [],
};
my $res = $client->call( $uri, $obj );
if($res){
if ($res->is_error) {
print "Error : ", $res->error_message;
}
else {
print Dumper($res->result);
}
}
else {
print $client->status_line;
}