[Reprinted] Use android to access a local site-(localhost, 10.0.2.2) must be different

Source: Internet
Author: User

Reprinted: http://weizhulin.blog.51cto.com/1556324/311704

 

Do you want to try using the android simulator to access your own web site? Next I will explain how to implement it.

Step 1: I use Tomcat as the local server. In the webapps directory, put my web project named kankong in and start the Tomcat server.

Enter http: // localhost (or 127.0.0.1): 8080/kankong/index.html in the browser. The following page is displayed:

 

Step 2: Start the android simulator:

If you have already started the android simulator in eclipse, skip this step. How can we manually start the android simulator?

First, run cmd to display our favorite black screen. Enter Android list AVD (list all AVD simulators)

 

 

Then we select one of them to start Android 1.5 as an example: emulator-Debug avd_config-AVD Android 1.5:

The image we are familiar with is as follows:

 

Step 3: Open the browser and enter http: // localhost: 8080/kankong/index.html?

Our first thought was to input http: // localhost: 8080/kankong/index.html, but this would not succeed. Why? The problem is that the android simulator uses itself as the localhost, that is,CodeAccess using localhost or 127.0.0.1! This cannot be done!

If you want to access your computer on the simulator, use the built-in Android IP address 10.0.2.2. 10.0.2.2 is the specific IP address set by the simulator and is the alias of your computer. Remember, use 10.0.2.2 to access your computer on the simulator.

That is, enter http: // 10.0.2.2: 8080/kankong/index.html to display the following interface:

 

OK ~ This is all done!

 

 

This article is from the "android_tutor" blog, please be sure to keep this http://weizhulin.blog.51cto.com/1556324/311704

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.