1

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

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

我也尝试过127.0.0.110.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());
    }
4

0 回答 0