简体   繁体   中英

android 4 emulator cannot connect with localhost

I want to connect with my web API, its URL is http://localhost:55154/ , with android emulator.

AsyncHttpClient client = new AsyncHttpClient();

client.get("http://10.0.2.2:55154/api/values", new AsyncHttpResponseHandler() {    
    @Override
    public void onSuccess(String response) {
        System.out.println(response);
    }
});

I'm getting no response, however, when I connect to google.pl I'm getting a proper response.
I have tried multiple variants with the localhost address, but none is working.

Im using this liblary for my async connection: http://loopj.com/android-async-http/

UPDATE:

When I'm running my program I'm getting the following error from the LogCat

07-17 08:58:26.495: E/Trace(879): error opening trace file: No such file or directory (2)

However I am able to conect with http://localhost:55154/api/values via my browser.

use the IP address 10.0.2.2 not 10.0.0.2

reference http://developer.android.com/tools/devices/emulator.html#networkaddresses

像这样使用http://10.0.2.2:55154/来连接您的端口地址

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM