Android Question My app can't access to my pc localhost for read data

RUNO

Active Member
Licensed User
Longtime User
My greetings

I tried to run the application on my mobile phone, but the application cannot access files on the PC .
On the emulator it works but on mobile it does not.
All possible addresses are used.
localhost
127.0.0.1
10.0.2.2
IPv4 Address
with ports 80,8080 and 82
Firewall off
Some time gives this message
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
ResponseError. Reason: Forbidden, Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
<address>Apache/2.4.51 (Win64) PHP/7.4.26 Server at 192.168.2.235 Port 80</address>
</body></html>
ResponseError. Reason: Forbidden, Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>


or this
ResponseError. Reason: java.net.ConnectException: Failed to connect to /127.0.0.1:80, Response:

Any idea to solve the problem ?
Thanks advance
 
Last edited:

aeric

Expert
Licensed User
Longtime User
This is a very frequent mistake and question being asked many times.
You need to understand what is a network where each device connected has its IP address assigned to it. What is localhost. What is local IP. What is public IP.
 
Upvote 1

zed

Active Member
Licensed User
In general port 80 is disabled by your ISP.
Here you are trying to connect with the address 192.168.2.235:80 which is a local ip.
If you enter the ip address in your browser, what happens?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
Try running 'Sheilds Up' (grc.com) to see if your ports are visible to the internet.
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Thank you for the clarification. I have read and watched the posts before and tried, but I still did not find the way
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Can you try explain in more detail and upload a small example.
What kind of files and location in your PC?
I want access to localhost on my pc from real device.
How I know ip address and port to access.
php ,image
It run on emulator but I want run it on my phone
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I want access to localhost on my pc from real device.
How I know ip address and port to access.
php ,image
It run on emulator but I want run it on my phone
How do you enable the local web server? wamp or laragon?
Check the port used in this app. It is usually set to 80 or 8000. If it is 80 then you can ignore the port number.

To check the local IP, use windows command prompt and type in ipconfig and check the IPv4 as in my YouTube video.
1686805522332.png
1686805605605.png



Second way:
At the time I recorded the video, there is no info for WiFi settings in Windows 11. Now I can use the WiFi settings to check my local IP.

1686804679386.png
1686804859055.png
 
Last edited:
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
How do you enable the local web server? wamp or laragon?
Check the port used in this app. It is usually set to 80 or 8000. If it is 80 then you can ignore the port number.

To check the local IP, use windows command prompt and type in ipconfig and check the IPv4 as in my YouTube video.
View attachment 142927 View attachment 142928


Second way:
At the time I recorded the video, there is no info for WiFi settings in Windows 11. Now I can use the WiFi settings to check my local IP.

View attachment 142925 View attachment 142926
Thank you, I used it before and said it in the first post but nothing
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Make sure you have forwarded the request to the correct local ip (192.168.50.42) for the specified port in your Router first.
Also make sure to assign always the same IP to this Computer in your router.
My network from mobile
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
The same applies to Mobile Hotspot.

Edit: Do you want to access from another mobile which is not the one hosting the Hotspot? Then the mobile device also need to connect to the Hotspot similar to your PC.
Yes , I have 2 mobiles
the link in app
B4X:
http://IPv4 address my pc:8000/w2/index.php
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Yes , I have 2 mobiles
Let say I have
Mobile 1 (Huawei) - HotSpot (IP: 192.168.10.254)
PC1 (Lenovo) - IP: 192.168.10.12
Mobile 2 (Xiaomi) - IP: 192.168.10.6

Mobile 1 is sharing the internet data to PC1 and Mobile 2.

PC1 should be able to open the PHP web app with address http://127.0.0.1 and http://192.168.10.12
Then you can check in your Mobile 2 using a mobile web browser try to open the PHP web app with address http://192.168.10.12
If you can open, then there should be no problem using okHttpUtils2 from your B4A app in Mobile 2.
 
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Let say I have
Mobile 1 (Huawei) - HotSpot (IP: 192.168.10.254)
PC1 (Lenovo) - IP: 192.168.10.12
Mobile 2 (Xiaomi) - IP: 192.168.10.6

Mobile 1 is sharing the internet data to PC1 and Mobile 2.

PC1 should be able to open the PHP web app with address http://127.0.0.1 and http://192.168.10.12
Then you can check in your Mobile 2 using a mobile web browser try to open the PHP web app with address http://192.168.10.12
If you can open, then there should be no problem using okHttpUtils2 from your B4A app in Mobile 2.
Thank's for the clarification
first I test my file in browser before
http://127.0.0.1 is ok
http:// ipv4

Hmmm… can't reach this page​

 
Upvote 0

zed

Active Member
Licensed User
If you can't connect locally to your web server, it's very likely that the problem is with your router.
Have you checked if the port used is open (eg: port 80). Routers provided by your ISP are blocked.
You cannot connect to your local web server. You need to change your router settings to do this.

I had this problem when I installed my development web server.
Also check your firewall
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
I want access to localhost on my pc from real device.
How I know ip address and port to access.
Sorry, it's not yet clear for me.

You have a PC, and 2 mobiles
How are them connected? Do you have the PC connected with wifi to a router and the mobiles phones too? If you're not in the same network, you won't be able to access to your local ip.

Are you connected througth your mobile phone hotspot? Hum... 10.0.2.2 seems a VPN network, you can't reach it from internet, and if you're using your mobile phone as a kind of router, probably you will find some problems, you can't open or redirect ports.

Please, post some kind of sketch of your network, something like this, or even simplier

1686821073650.png
 
Upvote 0
Top