1

I have implemented one Android application, which contains remote connection. My code is as follow: I am testing my app in my mobile device but I am getting error like:

Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to 127.0.0.1 refused

I have tried 127.0.0.1, 10.0.2.2 and my pc's ip address too, but nothing is working out.

    String url = "http://127.0.0.1/test.php";
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();

        httpPost.setEntity(new UrlEncodedFormEntity(param));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();           
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection "+e.toString());
    }
reVerse
  • 35,075
  • 22
  • 89
  • 84

0 Answers0