I need to access an external configuration file that is in json
format.
I have this code but it does not work for me:
String stringUrl = "url_to_json/configuracion.json";
String respuesta = "";
StringBuilder response = null;
try {
URL url = new URL(stringUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("charset", "utf-8");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
response = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
respuesta = response.toString();
} catch (Exception e) {
respuesta = "Error->" + e.getMessage();
}
Log.d(TAG, "Configuración Menu->" + respuesta);
The answer I get from the console is this:
Configuración Menu->Error->null