我正在尝试从 Java 连接到比特币钱包。但我得到网络异常:服务器重定向太多次。如果有人帮助我理解,我会很高兴。这是我的代码:
public static void SetupRPC() {
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication ("admin", "admin".toCharArray());
}
});
URL serverURL = null;
try {
serverURL = new URL("http://127.0.0.1:44843");
} catch (MalformedURLException e) {
System.err.println(e.getMessage());
}
JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
String method = "getinfo";
int requestID = 0;
JSONRPC2Request request = new JSONRPC2Request(method, requestID);
// Send request
JSONRPC2Response response = null;
try {
response = mySession.send(request);
} catch (JSONRPC2SessionException e) {
System.err.println(e.getMessage());
}
if (response.indicatesSuccess())
System.out.println(response.getResult());
else
System.out.println(response.getError().getMessage());
}
和 .conf 文件:
rpcuser="admin"
rpcpassword="admin"
rpcallowip=*
rpcport=44843
server=1
daemon=1
listen=1
rpcconnect=127.0.0.1