HttpURLConnection refused in mobile phone but not android emulator - php

I am currently doing POST request from android to PHP WAMP server. I am facing one problem, that is ,it refused to connect with the server (error 403) by using my mobile phone. On the other hand, my android emulator able to connect and perform POST action to PHP server.
String urlAddress = "http://192.168.43.133/Test/php_script.php";
HttpURLConnection con=Connector.connect(urlAddress);
int responseCode=con.getResponseCode();
In mobile phone debugger mode, I got 403 for the responseCode. Anyone faced this kind of problem before?

By default WAMPServer comes configured as a single desktop secure environment, to protect beginners form getting hacked.
So to access it from another device you must tell Apache that that is allowed.
Edit the httpd-vhosts.conf file. This is where the locahost Virtual Host is defined. Use the WAMPServer menu system.
wampmanager-> Apache -> httpd-vhosts.conf
Look for this line inside the ` and tag
Require local
If you want to allow access from your WiFi network then change it to comething liek this
Require ip 192.168.43
Note I used only 3 of the 4 quartiles. This says allow any ip address in the 192.168.43 range to connect to this Apache Virtual host
Try and avoid using
Require all granted
That is a hammer to crack a nut approach and if you ever open up your router would allow anybody in the universe to access your site.
Once you have edited the file and saved it, dont forget to restart Apache
wampmanager->Apache-> Service Administration->Restart Apache

This is network issue so make sure you have the following checked:
You firewall
Both your pc and phone are in the same LAN
Check if you can access your server from another device on the network

I had this issue, WAMP by defdault only accept conections coming from the same computer, so trying to access it from another device even though on the same network won't work, for that you need to first disable any firewall installed on your computer then go to windows firewall and add WAMP as an exception, and then try, if it doesn't work, then google how to allow connection from external devices to WAMP

Related

Send Request to a website in My PC local Host

I have a offline website installed on my localhost PC , I am using xampp with apache. I installed everything and I can access the website from browsers normally. But when I am trying to send any PHP POST or GET requests to this localhost from anywhere like PostMan or any other online website I got connection Refused Error. Also its happen with file_get_contents.
I don't have much experience in Windows firewall or apache configuration so I need advice for what can I do?
it was a CSF firewall error from the online server side. it was not allow me to send the requests outside the server without whitelisted the requested server :)
Thanks

how to rewrite -host-header in ngrok in order to open a sub-website in xampp running on localhost

I am trying to expose my website to internet, using ngrok, my website lives in xampp server which is running on my local machine. the path to my website is this: C:\xampp\htdocs\TheWebsite
when i use the following command for running ngrok client:
ngrok http -host-header=rewrite TheWebsite:8081
the client gets connected to ngrok server, but when i try to access my website on internet using http://234k2h4k24.ngrok.io which is the url ngrok provides for me, i end up with this error:
The connection to http://234k2h4k24.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address TheWebsite:8081.
Make sure that a web service is running on TheWebsite:8081 and that it is a valid address.
The error encountered was: dial tcp: lookup TheWebsite: no such host
how exactly one should set the value for -host-header switch in order to to get the sub-directories (websites) living in htdocs folder in xampp server environment??
I have searched this site and also all over the Internet and i found some quick answers but they confused me even more. like this one:
https://helgesverre.com/blog/expose-local-webserver/
which doesn't even provide a small example
and this: Tunnel a localhost subdirectory through ngrok?
just the same as previous one (no example)
A real good answer needs to provide at least one complete example (i mean, if you want to answer this question, please provide a full example of ngrok command for the path of my website (TheWebsite). thank you
for this purpose i needed to define virtual hosts for each of my websites!
I found the answer in a related question at stackoverflow.com and here it is:
Tunnel a localhost subdirectory through ngrok?
this question leads you to this page which lets you know how to define virtual hosts in order for your local machine to identify where is the requested website, just take a look and you will learn in it no time. here is the page:
http://forum.wampserver.com/read.php?2,127757
although its for wamp but it is the same for xampp server too!

Unable to connect to xampp server from android device

I am using BrainTree Payment service in my android app.For server ,I am using php and XAMPP. Now when I use emulator and access server with "http://10.0.2.2:80".
IP address, everything works fine but if I put my laptop's IP address(where server is running),it does't work on android device and emulator.
I am getting :
"Connection Timeout Error"
Thank You !It turned out to be McAfee was blocking the connection request..SO after disabling McAfee,it worked!
(1) make sure both your android device and your laptop are on the exact same wireless network. This has to be the same router so I would avoid testing in a public area where there may be many routers serving a network.
(2) sometimes your firewall a might be blocking incoming connections, temporarily disable it.
(3) double check you're connecting to the correct IP address in your code. CMD -> ipconfig, then it's ipv4
Make sure you are using the ipv4 that you see when you type ipconfig into command prompt.
Try to disable Windows Defender, change Apache's require all granted config among others and try disabling the Windows firewall.

Unable to access localhost using android mobile

Hello I have a problem in accessing the localhost in my android device. I can't open my localhost in my browser. I installed an application that supports httpd, php and mysql. But when I have a connection in the Internet there's no error in displaying the localhost. But if I disable it, I can't open the localhost. Is there a configuration file that I need to configure in my device? I am using ICS. I am using 127.0.0.1 as my localhost I also did 127.0.0.1:8080 but it doesn't work also.
If you're trying to access your web server over your local network, then you'll need to bind the web server to an IP address that the device can access - this is not 127.0.0.1. Assuming you're on wifi with your android, you'll want to have your web server listen to something along the lines of 192.168.1.X. If you use 0.0.0.0 it will accept on all interfaces, this should work as well. Either case, you'll need to access your web server from your device using your web server's local IP address, not localhost and not 127.0.0.1
Localhost as the url in a browser should access the server running on that device.it sounds to me maybe you are connected to a remote desktop or something. Tcp/ip utilities in particular try tracert localhoast or route. config /release maybe your touting tables are messed up,weird
The localhost refers to the device on which the code is running, in this case the emulator.
If you want to refer to the computer which is running the Android simulator, use the IP address 10.0.2.2 instead 127.0.0.1. You can read more from here.
I encountered the same problem while working with my localhost too. The problem turns out to be with the antivirus that i was using. I was able to access my locahost again after turning the antivirus off. But because i cannot continue using my machine without an antivirus I just have to change the antivirus to another one. It worked for me, Hope it will for you too.

testing php website on wampserver using android web browser

I am trying to test a php website using the web browser in android device (Google Nexus S). The Android version is 4.0.3. I have installed WampServer on my machine (running Windows 7) and have copied my php code in the wamp/www directory. I am able to test the code by browsing to localhost from the web browser on my machine. To test from my android device I tried browsing to my machine's public IP address, but the browser just gets stuck and doesn't load the page.
Does anyone know a solution to this problem ?
Thanks.
If you are browsing to your PUBLIC IP you need to ensure your Windows 7 firewall is allowing traffic on that port. Browsing from your localhost most likely works because your firewall doesn't block local traffic. Browsing to your PUBLIC IP means you are going out to the internet, hitting your firewall (router/windows 7?), and then trying to get to your server. Do you have port forwarding setup on your router? Have you tried accessing your local LAN IP rather than your public IP?
Here's what I did:
References :
http://forum.wampserver.com/read.php?2,13744
http://forum.wampserver.com/read.php?2,30970,30989
I changed Apache httpd.conf to listen at port 8080 instead of 80.
Also I added a new inbound rule in my windows firewall to allow port 8080 TCP connections.

Categories