Phone can't connect to PC to execute PHP file - android

I created a database in my PC, and now I want to retrieve all table data and display them on my phone usin Google gson library by executing a php file in the server. The problem is the phone can't connect to the PC to execute that php file:
Error 403 for URL http://192.168.1.2/android_connect/get_all_products.php
I'm sure that the code is working cause i tested with that online link and data are retrieved in the phone.
The url is like that in JAVA code:
String url = "http://192.168.1.2/android_connect/get_all_products.php";
Is that correct? Is there something to do to let the phone connect to the PC?
Thank you for helping.

You need to tune your PC's configuration to allow remote requests. Please see what error 403 is. It'd also help to check what's in your HTTPD logs concerning this request.

To allow remote access to apache on Windows change the file: c:\wamp\bin\apache\Apache2.2.22\conf\httpd.conf
You need to allow remote access to directory C:\wamp\www like this:(add that lines)
<Directory "C:/wamp/www/">
Order Deny,Allow
Allow from all
</Directory>
And RESTART YOUR SERVER.

Related

How to Post Data to Android App using Inbound Connection?

Is it possible to post data directly to an Android app from some URL on a local network using inbound connection?
Example: My Android device(Device 1) is running on local IP: xxx.xxx.x.146 and another Non-Android device(Device 2) is running on local IP: xxx.xxx.x.147. Device 2 only post data to URL. My requirement is to share Device 1 URL with Device 2, so that Device 2 can post data directly to Device 1 over same network. Any suggestions?
Thanks,
Gaurav Kapoor
I think you need to go with below way then it should be possible but rest cases not feasible please check below if it will help to you.
Option:1 with help firebase dynamic link to give data from url.
https://firebase.google.com/docs/dynamic-links/android/receive
Option:2 using some referral way for more details check below link
How to get Google Play referer in an Android application

OkHttp cannot fetch data from localhost

Can anyone please show me the way to fetch data from localhost by OkHttp in Kotlin. When i changed url to https, it worked well
Picture in Logcat for successful one
but when i use http://localhost..., it failed to execute
Picture when failed
EDIT - 8/23/22
It is likely you need to set
android:usesCleartextTraffic="true"
as a flag within the <application> element in the AndroidManifest.xml file.
Old Answer
don't use localhost like this. open command prompt if you are using Windows. type ipconfig and then get Local Ip Address and then use that Ip Address to get data from local host.
same method for Mac. you have to get local ip address

Posting Data To Sub-Domain URL on Localhost

Hello I am building my first android app, I am currently trying to post data to a URL on my local server. When I try with my live server it works however with my local server it does not, nothing happens at all, I get no response.
This is the route in my app on my localhost: http://admin.website.dev
I changed my hosts file and virtual host configuration on my localhost so that any address with the extension ".dev" points to a folder on my localhost. eg. "localhost/website"
Is there a reason this does not work in my android app when I try posting data?
I have already added the INTERNET permission in my manifest file.
Since android 5, you need to make a POST on DNS valid URL.
I'm not sure if your changes on hosts file will work.

Android emulator cannot connect with local tomcat server with HttpURLConeectioin

I'm doing a project to connect Android with local Tomcat server. But now I'm facing a problem for about 1 week. Who can help me..Thanks very much!
I use the newest android API and Tomcat 7.0. When I start Tomcat server. I can access the Tomcat homepage through emulator browser with url:(http://10.0.2.2:8080). But when I use HttpUrlConnection in the code. I cannot get the successful connection. I also use httpurlconnection to access www.google.com and www.android.com. I cannot connect them either.I use HttpURLConnection.HTTP_OK to see whether it make a successful connection. I also see the Connected is false for HttpURLConnection instance I make.
By the way I also add the internet access permission for it in AndroidManifest.xml before tag.
Thank you very much! Help me. It's emergency.
I recently had this problem. As mentioned above, (on Windows) start cmd, and use ipconfig to find the PC's IP address. Also, due to my Eclipse/Tomcat configuration I needed to have my Eclipse project name in the URL. The URL I used was like this: http://192.168.1.2/myEclipseProject/ServletName
Also, you may need to add the port to the ip address, if your Tomcat still has the default configuration: 192.168.1.2:8080

SmartFoxServer unable to connect to server

I am working in android chat application.
I used SmartFox server. I am using 10.0.2.2 as server IP address and 9933 as Port.
Whenever i run this application using emulator then works fine but when i run this application in my real device then connection does not performed correctly. I think this is unable to find out IP 10.0.2.2.
I changed this IP address to 192.168.1.9 which is IP address of my system in LAN on which SmartFox server is installed.
Please suggest me what mistake i have done.
Thank you in advance.
I resolved my problem myself. I created one entry in confi/server.xml file of server.
like this:-
<serverSettings>
<socketAddresses>
<socket address="192.168.1.9" port="22" type="TCP"/>
<socket address="192.168.1.9" port="22" type="UDP"/>
</serverSettings>
</socketAddresses>
or you may add this entry using admin module of Smartfox server. This task can be done using Server configuration part.

Categories

Resources