How to get data from deployd for use in an Android application?

I am trying to detect deployd, and I created a simple table to store data. The table is stored in

http://localhost:2403/table 

like JSONArray. I can get data with the following code:

private 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();
  }

  public static JSONArray 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);
      JSONArray json = new JSONArray(jsonText);
      return json;
    } finally {
      is.close();
    }
  }

public static void main(String[] args) throws IOException, JSONException {
    JSONArray obj = readJsonFromUrl("http://localhost:2403/table");     

}

My question is that this data is stored in the local host. Let's say I want to use this database in my Android application. Then obviously I can’t use

JSONArray obj = readJsonFromUrl("http://localhost:2403/table")

to get a json array. So how can I get this? I looked at the documentation and found nothing. Which link should I use instead of the local host: 2403 / table?

thanks

+4
source share
1 answer

, ip , Deployd, :
http://192.168.0.42:2403/table (192.168.0.42 IP- ).

, - .
, Heroku. :
https://gist.github.com/facultymatt/5373247

+2

Source: https://habr.com/ru/post/1526811/


All Articles