我可以在模拟器中连接到localhost,但不能在真实设备上连接
I really made research about this issue but nothing works for me. I am using WampServer and have a php webservice.
I wrote an app on Android Studio. I have a login.php
at localhost. On android emulator I use 10.0.2.2:8080/login.php
and everything works perfect. But on real device,it is not working. I tried
127.0.0.1:8080
(localhost)192.168.2.1:8080
(default gateway)192.168.2.60:8080
(IPv4 adress).
Nothing is working, what should I do? I hope somebody knows the answer
Thank you in advance
我真的对此问题进行了研究,但对我没什么用。 我正在使用WampServer并拥有一个php webservice。 p>
我在Android Studio上编写了一个应用程序。 我在localhost上有一个 什么都没有用,我该怎么办? 我希望有人知道答案 p>
提前谢谢 p>
div> login.php code>。 在Android模拟器上,我使用
10.0.2.2:8080/login.php code>,一切都很完美。 但在真实设备上,它无法正常工作。 我试过 p>
127.0.0.1:8080 code>(localhost)
192.168.2.1:8080 code>(默认网关)
192.168.2.60:8080 code>(IPv4地址)。 p>
I did suffer from the same problem from past 2 days, but I ultimately found the fix:
1)
Change the entry in httpd.conf:
#onlineoffline tag – don’t remove
Require local
to
#onlineoffline tag – don’t remove
Require all granted
Source: https://www.youtube.com/watch?v=XbBGYm14xY4
2) Change the entry in httpd-vhosts.conf:
<Directory “c:/wamp64/www/”>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
to
<Directory “c:/wamp64/www/”>
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
You should connect to local IP of your PC (you can check with ipconfig
/ifconfig
).
I guess that is 192.168.2.60:8080
you wrote. Then make sure you are on same network and that port 8080
on your PC is open.