Unable to contact host machine (10.0.2.2) from emulator

I have a python REST API server running on my laptop. I am trying to write a leisure client in Android (using Eclipse ADT, etc.) to contact him using the Apache client libraries (org.apache.http.client).

The code is really simple and basically does the following:

HttpGet httpget = new HttpGet(new URI("http://10.0.2.2:8000/user?username=tim"));
HttpResponse response = httpclient.execute(httpget);

However, when executing exceptions, throws a timeout exception. I can’t hit the URL even from the browser in the emulator.

Exception Details

org.apache.http.conn.ConnectTimeoutException: Connect to /10.0.2.2:8000 timed out

However, I tried using the cREST client in Chrome on my laptop, and I can request a REST server.

+5
source share
2 answers
0

, :

. . "http://localhost: 8000/user? Username = tim" . -, , , . python , . , , ( 10.0.2.2).

0

All Articles