The Android marketplace, developed by myself, started testing on a mobile phone and encountered a problem: "How does an app access the Tomcat server on a local computer on a mobile phone ", if you have some mobile application development experience, you must know that setting "localhost" or "127.0.0.1" is not acceptable. Setting the IP address to "10.0.2.2" on the simulator is accessible, but this method does not work on a real machine.
As a result, I began to search for solutions through the Internet in the following ways:
(1) Deploy the application backend server to a server that can be accessed through the public network. The mobile phone can access this public IP address, which is similar to a public network trial.
(2) set the LAN, and the mobile phone accesses a server in the LAN through WiFi (with a lan ip address)
Obviously, the above two methods are cumbersome and cannot be quickly switched to the test environment. Previously, I used to share my computer's network to enable my mobile phone to access the Internet, then you must access the Tomcat server on your computer. So it's much easier to switch to the test environment.
SolutionYes:
(1) Add an IP address to the local server (my IP address is set to 192.168.0.13)
(2) set the httpclient access address of the Android app to 192.168.0.13.
(3) set the Tomcat host, for example:
(4) Allow the mobile phone to share the Internet of the Local Computer (of course, the mobile phone must be set to debug mode),
Open the application to access the local server. The test passes ~~~~~~
Turn: http://www.chixijiu.com/Item.aspx? Id = 174