title: Android Emulator Connection to http://10.0.2.2 refused
body: <p>I got this error on an Android Emulator when I tried connecting to a local server:</p>
  
  <pre><code>I/System.out﹕ org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2 refused
  </code></pre>
  
  <p>This is the code that I used to connect to the local server (<a href="http://10.0.2.2/bank/login.php" rel="nofollow noreferrer">http://10.0.2.2/bank/login.php</a>):</p>
  
  <pre class="lang-java prettyprint-override"><code>HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost("http://10.0.2.2/bank/login.php");
  //HttpPost httppost = new HttpPost("http://10.0.2.2:80/bank/login.php");
  //HttpPost httppost = new HttpPost("http://10.0.2.2:8080/bank/login.php");
  
  try {
      List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
      nameValuePairs.add(new BasicNameValuePair("username", "Will"));
      nameValuePairs.add(new BasicNameValuePair("password", "password"));
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  
      HttpResponse response = httpclient.execute(httppost);
  } catch (IOException e) {
      // TODO Auto-generated catch block
      System.out.println("API LOGIN");
      System.out.println(e);
  }
  </code></pre>
  
  <p>Also, I've added <code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;</code> to the AndroidManifest.xml file. The content of my AndroidManifest.xml is:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.dev.will.test" &gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".LoginActivity" android:label="Login" /&gt;
  
          &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>There is no problem with the local server, since I can access to the url <a href="http://10.0.2.2/bank/login.php" rel="nofollow noreferrer">http://10.0.2.2/bank/login.php</a> from the browser of the Android Emulator without problem and also from another computer within network, but the connection is refused from my Android application.</p>
  
  <p>Please help me to figure out what can else I should configure to make it work on my app in the Android Emulator.</p>