无法从Android设备访问本地主机网络服务 [英] Cannot access localhost web service from Android device

查看:221
本文介绍了无法从Android设备访问本地主机网络服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与CakePHP的Web服务为我自己的测试目的。

I have built a web service with CakePHP for my own testing purpose.

现在我用我真正的Andr​​oid设备连接到我的web服务(@localhost)。在第一次尝试,我成功地加载我的测试页。然后,我关掉了Apache服务器并对其进行测试,以确保它不可用。在测试完成后,我再次重新启动Apache的。然而,自那时以来,我的Andr​​oid设备无法加载我的网页(网页不可用)。我有摘要式身份验证对我的web服务的文件夹,并在第一次尝试,它被正确执行...

Now I use my real Android device to connect my web service (@localhost). At first try, I managed to load my test page. Then, I turned off the Apache server and test it to make sure it is not available. After the test was done, I restarted Apache again. However, since then my Android device cannot load my page (Web page not available). I have Digest Authentication on my web service folder and at first try, it was properly executed...

我到目前为止所做的是:结果
1.连接我的本地主机( http://192.168.xxx.xxx )用我的真正的Andr​​oid设备(而不是模拟器)。结果
2.摘要式身份验证弹出。结果
3.输入用户名和放大器;密码。已成功连接。结果
4.关掉了A​​pache服务器。结果
5.尝试连接我的本地主机再次(当然,找不到网页)。结果
6.重新启动Apache服务器。结果
7.尝试重新连接我的本地主机(重装永远不会再工作......)

What I've done so far is:
1. Connected my localhost (http://192.168.xxx.xxx) using my real Android device (not an emulator).
2. Digest Authentication pops up.
3. Enter username & password. Successfully connected.
4. Turned off the Apache Server.
5. Try to connect my localhost again (of course, "web page not available").
6. Restart the Apache Server.
7. Try to connect my localhost again (reload never works again...)

起初我以为这可能是缓存问题什么的。因此,我已清除所有缓存和放大器;我的Andr​​oid的网络浏览器,并试图再次重新加载任何形式的数据。可是它永不再重装。然后,我试图从另一个PC连接,并连接成功。仅从Android设备无法刷新我的网页。

At first I thought it may be cache problem or something. So I have cleared all cache & any form data of my Android's web browser and tried reload again. But it never reload again. Then, I tried to connect from another PC and it successfully connected. Only from Android device fails to reload my page.

有什么我可以做,以解决这个问题?我需要用我的真实的Andr​​oid设备,因为模拟器是作业太慢调试的目的。我寻觅了一圈,发现几个类似的问题,但没有人也没有,因为帮助我的情况,我曾经成功连接到该服务。只是一旦失败重新加载页面,再也不会加载它...

Is there anything I can do to solve this problem? I need to use my real Android device for debugging purpose because the emulator is too slow for the job. I have searched around and found several similar questions, but none of them didn't help because in my case, I once have successfully connected to the service. Just once failed to reload the page and never load it again...

先谢谢了。

*编辑*
我只是用Android模拟器尝试相同的序列,并成功地重新加载...我已经甚至尝试另一个浏览器(海豚浏览器)为我的真实设备,仍然无法装入我的网页...

* EDIT * I just tried the same sequence using Android emulator and it successfully reloaded... I have even tried another browser (Dolphin Browser) for my real device and still cannot load my page...

推荐答案

也可能是Web服务器侦听的环回接口上而不是在网络接口上。这意味着,在 127.0.0.1 命中和本地主机将工作,但 192.168.xxx。 XXX 不会(无论是从本地主机,LAN或WAN)。

Possibly the web server is listening on the loopback interface but not on the network interface. This means that hits on 127.0.0.1 and localhost will work, but 192.168.xxx.xxx will not (whether from localhost, LAN, or WAN).

要确定该服务器监听哪个接口,看<一个href=\"http://www.commandlinefu.com/commands/view/702/lists-all-listening-ports-together-with-the-pid-of-the-associated-process#comment\"相对=nofollow>这里命令给大家介绍一下侦听端口(我用 lsof的-PAN -i TCP UDP -i )。然后查找在列表中的服务器进程。对于 lsof的命令,如果8888端口,你会看到类似 TCP *:8888(LISTEN)那么你的服务器侦听所有接口。但是,如果你不是看到类似 TCP [::127.0.0.1]:8888(LISTEN),那么你已经确定你的问题!

To determine which interface the server is listening on, look here for a command to tell you about the listening ports (I used lsof -Pan -i tcp -i udp). Then look for your server process in the list. For the lsof command, if for port 8888 you see something like TCP *:8888 (LISTEN) then your server is listening on all interfaces. But if you instead see something like TCP [::127.0.0.1]:8888 (LISTEN) then you have identified your problem!

接下来的步骤来解决你的问题是设置服务器的运行配置监听所有接口。我不知道什么CakePHP的,但如果你可以指定一个IP地址,那么你可能想尝试 0.0.0.0 。通常你可以做到这一点靠近它允许您指定的监听端口。因此,如果你有这样的配置:

The next step to solve your problem is to set up your server's run configuration to listen on all interfaces. I don't know anything about CakePHP, but if you can specify an IP address, then you may want to try 0.0.0.0. Usually you can do this near where it lets you specify the listening port. Thus, if you have a configuration like:

- 8888端口

这时可以尝试:

- 8888端口--address 0.0.0.0

这篇关于无法从Android设备访问本地主机网络服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆