调试中通过android simulator模拟器链接localhost或者127.0.0.1,因为我在电脑上面建立了apache,我的代码大概就是
URL url = new URL(urlString);
URLConnection urlconn = url.openConnection();

但是报错了!!

Exception 1:java.net.ConnectException: localhost/127.0.0.1:8080 -
Connection refused

问题是这样的,android模拟器(simulator)把它自己作为了localhost,也就是说,代码中使用localhost或者127.0.0.1来访问,都是访问模拟器自己!这是不行的!

如果你想在模拟器simulator上面访问你的电脑,那么就使用android内置的IP10.0.2.2吧, 10.0.2.2 是模拟器设置的特定ip,是你的电脑的别名alias

记住,在模拟器上用10.0.2.2访问你的电脑本机

文章出自:http://blog.csdn.net/junjieking/article/details/6612557

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. PianoView-添加一行代码使用[最美应用]的酷炫控件!
  3. android proguard混淆apk问题
  4. android所有需要的Demo地址
  5. Android(安卓)GridView的使用
  6. 学习Android闹钟源代码(三)-AlarmClock类分析(part2)
  7. 【译】如何在 Android(安卓)中使用 Retrofit, Moshi, Coroutines
  8. 定制自己的Home android
  9. Android(安卓)stutdio2.2 启动模拟器出现“/dev/kvm is not foun

随机推荐

  1. Android 设备管理器和有权查看使用情况的
  2. Android 软键盘盖住输入框的问题
  3. android 手机滤镜
  4. android HorizontalScrollView实现滚动监
  5. android自定义属性之format介绍
  6. Android - Jar mismatch! Fix your depen
  7. ListView.setOnItemClickListener 点击无
  8. Android(安卓)8.0 系统启动流程之init进
  9. android 完美退出所有Activity的demo
  10. APK 瘦身