Could you help me with my problem?
I am trying to access localhost to obtain the data from a table but I get an error HttpHostConnectException when i run it
COMPLETE ERROR: org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused
Code used:
public class MysqlConnectActivity extends Activity {
private TextView tv;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.TextView01);
}
private class DownloadPoints extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = "";
try {
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost/leerDatosUsuarios.php");
HttpResponse execute = client.execute(httppost);
InputStream content = execute.getEntity().getContent();
BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
String s = "";
while ((s = buffer.readLine()) != null) {
response += s;
}
}
catch (Exception e) {
Log.e("log_tag", "Error en la conexion HTTP: "+e.toString());
}
return response;
}
@Override
protected void onPostExecute(String result) {
tv.append("\nREAD FROM MYSQL:\n" + result);
}
}
public void readWebpage(View view) {
DownloadPoints task = new DownloadPoints();
task.execute( "http://localhost/leerDatosUsuarios.php");
}
Thank you for your attention
Alvaro
Localhost is your actual android device.
If you are trying to access your development machine, you need to access 10.0.2.2 from the emulator.