通过 android 连接本地主机 - 连接到 10.0.2.2 被拒绝 [英] Connecting localhost via android - Connection to 10.0.2.2 refused
问题描述
我的 PC 上安装了一个 apache 服务器,我在其中托管了一个 PHP 文件.
I have an apache server installed in my PC where I host one PHP file.
然后我尝试使用 eclipse 连接到该文件,但它总是给我以下错误
Then I tried to connect to that file using eclipse, but it always gives me below error
connection to http://10.0.2.2:8080 refused.
我尝试将地址更改为以下内容,但一直出现类似错误.
I tried changing address to the followings, but got similar error all the time.
http://10.0.2.2
http://127.0.0.1
http://localhost
谁能帮帮我.
仅供参考,我可以毫无问题地访问远程服务器(例如 www.mydomain.com).
类文件:
HttpClient httpclient = new DefaultHttpClient();
Log.d("test","t0");
HttpPost httppost = new HttpPost("http://10.0.2.2:8080/mylibman/data.php");
Log.d("test","t1");
HttpResponse response = httpclient.execute(httppost); // error here
Log.d("test","t2");
Android 清单:
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.migrationdesk.mylibman"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
错误日志:
11-16 02:02:20.803: E/log_tag(1427): Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused
11-16 02:02:20.803: E/log_tag(1427): Error converting result java.lang.NullPointerException: lock == null
11-16 02:02:20.803: E/log_tag(1427): Error parsing data org.json.JSONException: End of input at character 0 of
推荐答案
好的去 Apache httpd.conf(位于 Apache 文件夹中):并搜索
alright go to Apache httpd.conf (located in Apache folder): and search for
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
并检查第二行是否为拒绝,如果是则将其更改为:
and check if the second line is Deny, if it is then change it to:
Allow from all
然后重新启动 Appache 服务器,并告诉我反馈.
then restart the Appache server, and tell me the feadback.
<强> 编辑强>
在您的真实设备上试用:
try it out in your real device:
转到 CMD 并在 IPv4 下键入 ipconfig
获取 IP 地址并更改 IP,它看起来类似于:
go to CMD and type ipconfig
under IPv4 take the IP address and change the IP it will look similar to this:
http://192.168.0.106:8080/mylibman/data.php // similar to this.
关闭电脑中的防火墙和任何防病毒应用程序
请给我反馈.
这篇关于通过 android 连接本地主机 - 连接到 10.0.2.2 被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!