<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160810</version>
</dependency>
I'm trying to send a simple request:
protected static void checkBalances() throws JSONException, IOException, InterruptedException {
StringBuilder urlBuilder = new StringBuilder("
https://blockscout.com/etc/mainnet/api?module=account&action=balance&address=0x37802776D2A1654C8888da63757e0Df4440DA79B");
JSONObject results = readJsonFromUrl(urlBuilder.toString());
System.out.println("*"+results+"*");
System.exit(1);
}
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
return new JSONObject(jsonText);
} finally {
is.close();
}
}
protected static String readAll(Reader rd) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
flies in response
the same request in the browser gives
{"message":"OK","result":"840524398469120","status":"1"}
what am i doing wrong please tell me