I am starting to use a basic implementation of Bitcoin JSON RPC (dzhuvinov library), and I am getting a strange result. Here is my code:
public static void main(String[] args)
{
URL serverURL = null;
final String rpcuser ="user";
final String rpcpassword ="pass";
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (rpcuser, rpcpassword.toCharArray());
}
});
try {
serverURL = new URL("http://127.0.0.1:18332/");
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
return;
}
JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
String method = "getinfo";
int requestID = 0;
JSONRPC2Request request = new JSONRPC2Request(method, requestID);
JSONRPC2Response response = null;
try {
response = mySession.send(request);
} catch (JSONRPC2SessionException e) {
System.err.println(e.getMessage());
return;
}
if (response.indicatesSuccess())
System.out.println(response.getResult());
else
System.out.println(response.getError().getMessage());
}
And the response I am getting is:
Invalid JSON-RPC 2.0 response
Just to note - when executing this Python script:
access = jsonrpc.ServiceProxy("http://user:[email protected]:18332/")
print access.getinfo()
I get a proper results.
What might be causing this problem and how should I go about fixing it?