0

I have a simple webservice (at 127.0.0.1:8000) that return a JSON. If i test the webservice from a browser (Edge, Firefox, any other) i get the JSON as expected. But from the Android code (an emulator on Android Studio) there is no answer. The webservice never respond. At follow i paste the code :

@Override
protected Void doInBackground(final Void... params) {
    List<MotivoFallaEntity> motivoFallaEntityList = new ArrayList<>();
    try {
        final String url = "http://192.168.0.6:8000/getPieceFaultReasons";
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        motivoFallaEntityList = restTemplate.getForObject(url, MotivoFallaEntityWrapper.class);
    }
    catch (Exception e)
    {
        Log.e("Loggin", e.getMessage(), e);
    }

    mDb.motivoFallaDao().insertAll(motivoFallaEntityList);
    return null;
}

The IP address in the Android code (192.168.0.6) is the one that throws me the result of the command IPCONFIG.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Possible duplicate of [why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client](https://stackoverflow.com/questions/9808560/why-do-we-use-10-0-2-2-to-connect-to-local-web-server-instead-of-using-computer) – Gilles-Antoine Nys Jun 11 '18 at 14:48

1 Answers1

0

Android Studio emulators (AVD) have 10.0.2.2:8080 port as locahost. So, you should try

final String url = "http://10.0.2.2:8080/getPieceFaultReasons";

EDIT: more info in similar question on SO: explanations

ett3rnity
  • 1
  • 1