Android模拟器(simulator)把它自己作为了localhost,也就是说,代码中使用localhost或者127.0.0.1来访问,都是访问模拟器自己!这是不行的!
如果你想在模拟器simulator上面访问你的电脑,那么就使用android内置的IP 10.0.2.2 吧,10.0.2.2 是模拟器设置的特定ip,是你的电脑的别名alias
记住,在模拟器上用10.0.2.2访问你的电脑本机。

详细请参考Android文档android-sdk-windows\docs\guide\developing\devices\emulator.html下的Emulator Networking

Network Address Description
10.0.2.1 Router/gateway address
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
10.0.2.3 First DNS server
10.0.2.4 / 10.0.2.5 / 10.0.2.6 Optional second, third and fourth DNS server (if any)
10.0.2.15 The emulated device's own network/ethernet interface
127.0.0.1 The emulated device's own loopback interface

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. android 使用html5作布局文件: webview跟javascript交互
  6. Android(安卓)Resource介绍和使用
  7. "Failed to fetch URL https://dl-ssl.google.com/android/repos
  8. 使用NetBeans搭建Android开发环境
  9. android 零星调试笔记

随机推荐

  1. Program type already present: XXXXX
  2. Android实现的ListView分组布局改进示例
  3. SpyNote5.0 Client_APK逆向分析
  4. EventBus第一章:初识,相见,了解,使用
  5. Android——View.inflate()的详细介绍
  6. Android问题集锦之二十一 No resource fo
  7. Android(安卓)PendingIntent.getBroadcas
  8. ListView 实现阻尼回弹效果 并去除边缘阴
  9. android中如何实现连续点击返回键退出整
  10. android位移动画的两种实现方式