Kirti Umrigar
Kirti Umrigar

Reputation: 87

Error in http connection org.apache.http.conn.HttpHostConnectException: Connection to <ip address> refused

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());
    }

Upvotes: 1

Views: 1659

Answers (0)

Related Questions