简体   繁体   中英

How can I access my localhost through Android phone?

I want to connect my Android phone to XAMPP server of my pc to run my app on phone's browser (app is working fine with pc's browser).

I am using broadband connection. The only solution which I've got until date is through using wifi connection.

But, I am restricted to use LAN connection. How can I connect it without using a router?

its very simple , - GOTO command line (Window + R [type cmd]) - type ipconfig , that will show the current IP address of your PC - write taht IP address on your Android Phone's browser with :80 eg ( http://192.168.xx:80 )

Done

localhost will appear on your Phone

  1. Retrieve your IP address:
    In Ubuntu: type ifconfig in terminal
    In Windows: type ipconfig in cmd`
  2. Disable your Firewall
    In Ubuntu: type sudo ufw disable in terminal
    In Windows: Go to "Control Panel> System and Security> Windows Firewall" and turn it off.
  3. Insert retrieved IP address into your phone browser.
    (Your XAMPP local server must be running)
    Well done!

USB doesn't provide network to mobile device. If it's connected to your wifi, then hit your laptop address provided by the router. If it's connected to your mobile network, then first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device.

source: https://stackoverflow.com/a/4779992/1932105

or this:

It is very simple

Turn on Wifi Hotspot of your android phone and connect your Laptop with your phone.

Start your server at localhost (I am using wamp server)

Now open command prompt and enter ipconfig command you will get following things

 Wireless LAN adapter Wireless Network Connection: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::80bc:e378:19ab:e448%11 IPv4 Address. . . . . . . . . . . : 192.168.43.76 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 192.168.43.1 

Copy this 192.168.43.76 in your mobile browser.

Note : Please set you network as "Home Network".

source: https://stackoverflow.com/a/15864222/1932105

please use the search next time.

It is very simple, just follow this steps:

  1. Get your PC's IP address by typing IPCONFIG command in command prompt.
  2. Copy your IP address from the list which is under the wifi configuration area.
  3. In your android app code specify your IP Address.
  4. very important step put your server on-line .

If you are using ubuntu please go through this to find your local IP Address on the network and append it to the url instead of local host . worked for me

Eg : http://192.168.1.10/qrstuff/json/

So, I was recently trying to do the same... I am using a framework like Opencart. Which allowed me yo use "localhost" as host name to run my initial setup. If you did the same. Go back to your config.php for your app and change the HTTP_SERVER from localhost to your ip address(found from techniques above). You must do it in your DB_HOSTNAME also. And you will need to either edit or create a new DB user that uses the ip address as the HOSTNAME. You create and modify DB Users in the phpMyAdmin of XAMPP.

Then instead of http://localhost/yourapp_path/ it will be: http://your.local.ip.address/yourapp_path/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM