解决方案 »

  1.   

    经过我艰辛的寻找,终于找到一篇文章,希望新手们可以少走一些弯路。
    Android模拟器访问本地Web应用一个早上就是想让android的模拟器可以访问到web的应用程序,但是一直是不可以,弄的不知所措。On Windows, open the Control Panel, choose Programs, and click Turn Windows Features On or Off. Check the box labeled Internet Information Services and then click the + to its left; continue to drill down into World Wide Web Services→Application Development Features, then check the box to enable CGI (you’ll need the CGI feature to install PHP in Chapter 6, Going Offline). Click OK. After you’ve done this, you can put your web documents in your IIS document root, which is typically located at C:\inetpub\wwwroot. Try this with the test.html file you created in Chapter 1, Getting Started; you should be able to load that file by going to http://localhost/test.html in your browser.You’ll probably need to authenticate each time you put files into that folder. To work around this problem, you can either use the IIS Manager (Start→Control Panel→System and Security→Administrative Tools) to add a new virtual directory in a folder you have permissions to modify, or you can give yourself control of C:\inetpub\wwwroot (right-click on the folder, choose Properties→Security, and then click Edit→Add, type your username, click OK, then allow Full Control and click OK). If you want to connect to your Windows web server, even over your local network, you’ll need to go into the Control Panel→System and Security→Windows Firewall→Allow A Program or Feature Through Windows Firewall and enable World Wide Web Services.有一段资料是配置自己的电脑,就像上面说的那样:打开控制面板--选择程序和功能--点击左边的开启或关闭windows功能--然后选则CGI,等等...试了很久还是不可以。后来在上面查的时候看到的是有一段资料的介绍:如何在Android模拟器上访问本地的Web应用? 例如,在你的开发机器上启动一个Tomcat服务,接着打开电脑上的浏览器,默认情况下输入http://localhost:8080/就能够访问到Tomcat的主页面;那么,如果我们想在Android模拟器上来访问,可以吗?答案是肯定的,但是访问的URL会有所变化,这又是为什么呢?请继续往下看。
            在一般的Java Web程序开发中,我们通常使用localhost或者127.0.0.1来访问本机的Web服务,但是如果我们在Android模拟器中也采用同样的地址来访问,Android模拟器将无法正常访问到我们的服务,这是为什么呢?我们可以这样来理解:Android的底层是Linux kernel,包括Android本身就是一个操作系统,因此,这时我们在模拟器的浏览器中输入的localhost或127.0.0.1所代表的是Android模拟器(Android虚拟机),而不是你的电脑,明白了吗?这就是为什么你在模拟器中使用localhost时会报“Web page not available”的原因。        那到底要如何才能访问到本地电脑上的Web应用呢?在Android中,将我们本地电脑的地址映射为10.0.2.2,因此,只需要将原先的localhost或者127.0.0.1换成10.0.2.2,就可以在模拟器上访问本地计算机上的Web资源了。
            那下面我们就启动电脑上的Tomcat,然后运行Android模拟器,打开模拟器上的浏览器,然后访问:http://10.0.2.2:8888 是不是已经看到那只可爱的Tomcat猫了呢?访问截图如下图所示。(说明:在我的电脑上,Tomcat服务使用的端口是8888,默认情况是8080)图:试用了,很受用。O(∩_∩)O~呵呵 
      

  2.   

    我在自己的手机浏览器中输入网址http://10.0.2.2:8080/,还是没有显示出相应网页???
      

  3.   

    首先 你要建立一个Tomcatt服务器 你建立了吗
      

  4.   

    楼主,我的和你的是一样的问题,程序也都差不多,我传入的url现在改成了http://10.0.2.2:8080/mp3/resources.xml,但是还是不能传入,提示我是null,是什么原因呢?