通过Android的本地主机连接 - 连接到10.0.2.2拒绝 [英] Connecting localhost via android - Connection to 10.0.2.2 refused
问题描述
我有我的承载一个PHP文件安装在我的电脑Apache服务器。
然后我试图使用Eclipse连接到该文件,但它总是给我下面的错误
连接http://10.0.2.2:8080拒绝。
我试图改变地址以下几点,但得到了类似的错误所有的时间。
http://10.0.2.2
http://127.0.0.1
HTTP://本地主机
任何人都可以请帮助我。
编辑:。只为信息,我可以接触到偏远的服务器(如www.mydomain.com)没有任何问题
类文件:
HttpClient的HttpClient的=新DefaultHttpClient();
Log.d(测试,T 0);
HttpPost httppost =新HttpPost(http://10.0.2.2:8080/mylibman/data.php);
Log.d(测试,T1);
HTT presponse响应= httpclient.execute(httppost);这里//错误
Log.d(测试,T2);
Android清单:
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.migrationdesk.mylibman
安卓版code =1
机器人:VERSIONNAME =1.0>
<用途-SDK
安卓的minSdkVersion =11
机器人:targetSdkVersion =18/>
<使用-权限的Android:名称=android.permission.INTERNET对/>
错误LogCat中:
2月11日至一十六号:02:20.803:E / log_tag(1427):错误的HTTP连接org.apache.http.conn.HttpHostConnectException:连接到http://10.0。 2.2:8080拒绝
2月11号至16号:02:20.803:E / log_tag(1427):错误转换结果显示java.lang.NullPointerException:锁== NULL
2月11号至16号:02:20.803:E / log_tag(1427):错误分析数据org.json.JSONException:输入的字符0结束
好了去Apache的httpd.conf(位于Apache的文件夹),然后搜索
订单拒绝,允许
所有拒绝
从127.0.0.1允许
和检查第二行是拒绝,如果是则改变为:
所有允许
然后重新启动Appache服务器,并告诉我feadback。
修改
尝试一下你的真实设备:
去CMD,然后键入 IPCONFIG
下采取的IPv4的IP地址,并更改IP也将类似于此:
http://192.168.0.106:8080/mylibman/data.php //与此类似。
关闭防火墙和所有反病毒程序在你的电脑
和请给我反馈。
I have an apache server installed in my PC where I host one PHP file.
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
Can anyone please help me.
EDITED: Just for information, I can access to remoter server (e.g. www.mydomain.com) without any problem.
CLASS FILE:
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 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" />
Error LogCat:
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
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
then restart the Appache server, and tell me the feadback.
Edit
try it out in your real device:
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.
Turn Off the firewall and any anti-virus application in your PC
and please give me the feedback.
这篇关于通过Android的本地主机连接 - 连接到10.0.2.2拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!