我在我的 PC 上安装了一个 apache 服务器,我在其中托管了一个 PHP 文件。
然后我尝试使用 eclipse 连接到该文件,但它总是给我以下错误
connection to http://10.0.2.2:8080 refused.
我尝试将地址更改为以下内容,但始终出现类似的错误。
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 list :
<?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 文件夹中):并搜索
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
并检查第二行是否为 Deny,如果是则将其更改为:
Allow from all
然后重启Appache服务器,并告诉我反馈。
编辑
在你的真实设备上试试:
转到 CMD 并在 IPv4 下键入 ipconfig
获取 IP 地址并更改 IP,它看起来类似于:
http://192.168.0.106:8080/mylibman/data.php // similar to this.
关闭您 PC 中的防火墙和所有防病毒应用程序
请给我反馈。
关于android - 通过 android 连接本地主机 - 连接到 10.0.2.2 被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20015883/