我希望使用Android模拟器连接我的网络API,其网址为http://localhost:55154/
。
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);
}
});
但是,当我连接到google.pl
时,我没有得到任何回复。我得到了正确的答复。
我已尝试使用localhost地址的多个变体,但没有一个正在运行。
我使用此liblary进行异步连接:
http://loopj.com/android-async-http/
更新
当我运行我的程序时,我从LogCat收到以下错误
07-17 08:58:26.495: E/Trace(879): error opening trace file: No such file or directory (2)
但是我可以通过浏览器与http://localhost:55154/api/values
保持一致。
答案 0 :(得分:0)
使用IP地址10.0.2.2
而非10.0.0.2
参考http://developer.android.com/tools/devices/emulator.html#networkaddresses
答案 1 :(得分:0)
使用此http://10.0.2.2:55154/
来连接您的端口地址