I use the following code to access a multichain I have setup in AWS.
// params
String username = "lorem";
String password = "ipsum";
String server = "xxx.xxx.xxx.xxx";
String port = "xxxx";
String chainName = "chain1";
// json
Map<String,String> params = new HashMap<>();
params.put("method", "getinfo");
params.put("id", "1");
params.put("chain_name", chainName);
String jsonData = encode(params);
System.out.println(jsonData);
String login = username + ":" + password;
String base64login = new String(Base64.getEncoder().encode(login.getBytes()));
// build request
String url = "http://" + server + ":" + port;
System.out.println(url);
Document doc = Jsoup.connect(url)
.header("Authorization", "Basic " + base64login)
.header("Accept", "application/json")
.header("Accept-Encoding", "gzip,deflate,sdch")
.header("Accept-Language", "en-EN,es;q=0.8")
.header("Connection", "keep-alive")
.header("X-Requested-With", "XMLHttpRequest")
.data(jsonData, "")
.post();
// send
System.out.println(doc.toString());
This code, when executed, throws a 401 error.
The multichain.conf file looks like this:
rpcallowip=0.0.0.0/0
rpcuser=lorem
rpcpassword=ipsum
(obviously I changed the username and password)
What am I doing wrong?