Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
843 views
in Technique[技术] by (71.8m points)

eclipse - Connecting localhost via android - Connection to 10.0.2.2 refused

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 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...