http连接错误org.apache.http.conn.HttpHostConnectException:连接到<ip address =“”>拒绝</ip>

时间:2014-10-30 09:39:48

标签: android httphostconnectexception

我已经实现了一个包含远程连接的Android应用程序。 我的代码如下:我正在我的移动设备上测试我的应用程序,但我收到的错误如下:

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

我已经尝试了 127.0.0.1 10.0.2.2 我的电脑的IP地址,但没有任何问题。

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

0 个答案:

没有答案