Android phone and emulator cannot access WAMP web service - php

I have setup WAMP on my computer and have created a PHP web service which is located at this URL
http://localhost/WebService/?mode=get
I am using Android Studio and running the project on my Nexus 5 phone. Both the development computer and my phone are connected to the same wifi network.
When I try and call that URL from the application I get an error:
Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused)
In my manifest I have the internet permission.
How can I access a local web service from my attached phone for dev/debug?

Emulator uses a special ip address to access the host machine local host. Use this link
http://10.0.2.2/WebService/?mode=get
In some cases you might have to assign a port other than default.

Check your URL from your emulator or from the device... if you are not able to access it, Find the right url....
Open command prompt->type ipconfig-> Get IPV4 address.... something like 192.xx...
So your URL is "http://192.xx.xx.xx/WebService/?mode=get"
To access your local host from your android emulator Use the ip address given in ipconfig.

It might be best to use
machine_name.local
as the host name, as your server/computer could change IP address if you are using DHCP

Related

Not able connect mobile to WAMP

I am using WAMP(version 2.4.9) to host a local server on my pc. My pc is connected to wifi and the ip address is 10.192.48.252 . The port is 420. When I type http://10.192.31.222:420/ in the browser of pc, I get the wampserver homepage as it should be but when I type in the same address in my mobile browser, I get the following error
Forbidden
You don't have permission to access / on this server
I have connected both my pc and mobile over same wifi network. I have set "Require all granted" in httpd.conf file and made 420 accessible through firewall. Please help.
I was also having the same issue as yours. Try XAMPP. Its working fine for me. It has no port issue.

External XAMPP Access With Modem

I'm trying to create a live web server on my Windows 8.1 computer.
I am connected directly to my modem using ethernet (I do have a wireless router) but I am not connected to it on this computer (desktop).
I have XAMPP working and my website appears at http://localhost/home
However, if I put in my IP from www.whatismyip.com it does not load my web server.
What am I missing?
You need to create a Port Forwarding for Port 80 to your Computers local IP Address. There should be a Admin Panel for your Router (normally the Gateway - check out with Start - Run - cmd -> then insert "ipconfig" and check out the Gateway.
And i guess in XAMPP the Internet Access is blocked. But this is a simple Apache Server, so you need to open your httpd.conf File (Should be: “c:\xampp\apache\conf\extra\httpd-xampp.conf)
Search here for:
There should be a "Deny from all" - add a # in Front to deactivate that rule.
Restart your Xampp and it should work.
Here you find more Information about Port-Forwarding:
https://managewp.com/how-to-access-a-local-website-from-internet-with-port-forwarding
Any maybe you will also need to activate Port 80 on your Firewall (depends on your Configuration)
You need a method of telling request sent to your public ip to be forwarded to the private ip of the web server. Try logging into you device (router etc) and setting this up.

Android: What is the Correct URL to use to when connecting Android to PHP using local host?

I am unsure of what url to use for my application to connect to my WAMP server on local host.
Currently I am using:
String link = "http://10.0.2.2/login.php?username="
Is this correct or is should it be something else?
e.g.:
String link = "http://localhost/login.php?username="
None of them, first open cmd to find out your computer ip by command ip config and then go to firewall and enable port 80 listening and use that ip address.
look at this :
http://josephshaaia.wordpress.com/2012/12/22/connecting-android-device-to-a-database-on-mysql-wamp-server/

Not able to connect android app running on phone with localhost

I am making an Android Application using GCM. I am trying to register through my app running on phone, the inputs are not able to store on localhost XAMPP using php. My phone and laptop are running on the same network. There is some problem with the ip address of localhost. I am using this url for saving on local host, where 192.168.43.247 is the ip address when pc is running with the help of phone's 3G network.
192.168.43.247/gcm_server_php/register.php
Please help!
Open Xampp>apache>conf>http-conf file in notepad.
Find Listen 80 and comment out using #(like #Listen 80) and write below it: Listen (static ip address of server):80
eg:
Listen 192.168.1.34:80
If you want to use your application on emulator with localhost database(Xampp) then you have to use the IP address 10.0.2.2 instead of other local ip address .. if you want to use your aap on mobile then you you can use same ip .. press up arrow on left side if my answer is usefull for you
try to check by disabling firewall or use ipconfig /all command then get your ip from there and use this ip as server ip address.
If still facing error then it might be error of your local server the request may be block or something else that you need to find out.to check it try to open url in your android mobile browser.

canot establish connection to localhost through facebook application

i have created a new Facebook application and i used the following url as canvas url http://localhost/my_app/
my code works perfectly on localhost, but when i try to cal my application using the following url : apps.facebook.com/leenaaps its displays the following error:
Unable to connect
Firefox can't establish a connection to the server at localhost
what could be the problem exactly?
You most likely do not have a local webserver running. If you do, it might be possible that Facebook uses https:// but you did not configure/enable SSL.
localhost is resolved to ip 127.0.0.1 and this is the local loopback address whcih means it is not routable and cannot be accessed from the internet, So you cannot use it in your canvas url.
You have to use a valid and active domain name like domain.com. If you don't have a public web server you may use some DDNS service, google it some are free

Categories