リモート接続を含む 1 つの 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、およびPC の 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());
}