Jimmy Hill
Jimmy Hill

Reputation: 216

URL Connect to XAMPP Server using Android Emulator

I am writing a program in which i am trying to store data into XAMPP Server via Android Emulator, but i am getting error while inserting data into XAMPP.

Error: Unknown Status!

and i dam sure that i am getting this error because i am not using correct url to connect

Please check my below url to connect to XAMPP Server via Android Emulator:

   String url = "http://ipaddress/test.php"

I have tried this by using my IP address also, but whenever i browse it on browser getting Object Not Found:

The requested URL '/test.php' was not found on the RomPager server

  String url = "http://127.0.0.1/test.php"

  String url = "http://10.0.2.2/test.php"

Note : I have tested my php code before and it works fine, so something wrong in my URL

I am using below lines in PHP Script:

$objConnect = mysql_connect("localhost","root","") or die("Cannnot Connect to Database");
    $objDB = mysql_select_db("registration");

Upvotes: 1

Views: 10746

Answers (5)

Ercan
Ercan

Reputation: 2811

Xampp was working with Port: 80 as shown in below image. So writing below ip address as http://10.0.2.2:80/ worked for me. Hope this helps someone.

Xampp

Upvotes: 0

anas
anas

Reputation: 143

View this https://developer.android.com/studio/run/emulator-networking.html

use this "10.0.2.2" ip address it is equal to localhost in your hosting device

Upvotes: 0

Akshay Choulwar
Akshay Choulwar

Reputation: 34

Add to build.gradle:

Android{
    useLibrary 'org.apache.http.legacy'
}

Upvotes: -1

Pihhan
Pihhan

Reputation: 808

You cannot link to localhost (127.0.0.1), as emulator has its own network address and its own, separate localhost. So

    http://127.0.0.1/

connects to emulator itself. Unless you have android web server running, you will get connection refused error.

You can use ADB from Android SDK to forward ports from local PC to android device. But I think you cannot forward port from android device to PC. See adb forward help, but I believe it is another direction.

Easiest way to get it working is to use name of your computer instead localhost. You have to use real IP accessible from network, you can find that using ipconfig. Depending on your network configuration, you may be able to use full hostname with domain. Ie. mycomputer.example.org. Just append DNS suffix from ipconfig and try.

You may have to reconfigure your apache to listen also on external address and use firewall to block access from outside. If you use virtual host for 127.0.0.1 on apache server, you have also move it to virtual host with another address.

And it seems %SYSTEM%/drivers/etc/hosts file will not work, it has to be name nslookup can resolve. Easier is to use local IP, if that is not changing often. In other case, use dyndns :)

Upvotes: 0

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

127.0.0.1 its means localhost

insted of that Use your PC(Personal Computer)'s IP Address.

like:

if my pc's ip is: 192.168.0.1 then URL is

String url = "http://192.168.0.1/test.php"

Upvotes: 0

Related Questions