我正在使用xampp apache服务器从我的机器向应用程序提供资源。但我收到上述错误。
我在Google上找到了东西。在这里指向可能的解决方案 http://groups.google.com/group/android-beginners/browse_thread/thread/599a06416fb37b4a
以上问题的解决方案是什么?
我正在使用xampp apache服务器从我的机器向应用程序提供资源。但我收到上述错误。
我在Google上找到了东西。在这里指向可能的解决方案 http://groups.google.com/group/android-beginners/browse_thread/thread/599a06416fb37b4a
以上问题的解决方案是什么?
Answers:
由于未指定您已从设备或仿真器连接到服务器,因此我想您正在仿真器中使用应用程序。
如果要从Android模拟器引用系统上的本地主机,则必须使用,http://10.0.2.2:8080/因为Android模拟器在虚拟机中运行,因此此处127.0.0.1或localhost将是模拟器自己的环回地址。
参见:模拟器联网
http://localhost:8080/Getdata.php或者http://127.0.0.1:8080/Getdata.php您必须将其更改为使用http://10.0.2.2:8080/Getdata.php
10.0.2.2用10.0.3.2,如果你是在Genymotion运行。
在Android中
更换: String webServiceUrl = "http://localhost:8080/Service1.asmx"
与: String webServiceUrl = "http://10.0.2.2:8080/Service1.asmx"
祝好运!
本地主机和127.0.0.1都是说“当前机器”的方式。因此,您PC上的localhost是PC,而android上的localhost是电话。由于您的手机没有运行网络服务器,因此它将拒绝连接。
您需要获取计算机的IP地址(使用Windows上的ipconfig进行查找),然后使用该IP地址代替127.0.0.1。根据您的网络/防火墙的设置,这可能仍然不起作用。但这是一个完全不同的话题。
使用权限android:name =“ android.permission.INTERNET
如果您在URL中使用localhost并在模拟器中测试应用程序,则只需在URL中将系统的IP地址替换为localhost。或者您可以使用10.0.2.2而不是localhost。
http://localhost/webservice.php到http://10.218.28.19/webservice.php
其中10.218.28.19->系统的IP地址。
要么
http://localhost/webservice.php到http://10.0.2.2/webservice.php
您只需要使用本地IP地址即可:使用cmd命令“ ipconfig”和服务器端口号,如下所示:
字符串webServiceUrl =“ http://192.168.XX:your_local_server_port / your_web_service_name.php ”
并确保您确实在项目清单中设置了互联网许可
对我来说很好
祝好运
解决方法很简单。
1在Androidmanifest.xml文件中添加Internet权限
<uses-permission android:name="android.permission.INTERNET" />
[2]更改您的httpd.config文件
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
TO
Order Deny,Allow
Allow from all
Allow from 127.0.0.1
And restart your server.
[3]最无能为力的一步。 使您的网络成为您的家庭网络
转到控制面板>网络和Internet>网络和共享中心
Click on your Network and select HOME NETWORK