Android HTTP Get
He visto algunas publicaciones en el foro y no puedo encontrar una respuesta a mi problema. Estoy tratando de obtener una respuesta de un archivo php. El archivo php está funcionando. El problema es que la aplicación de Android no ejecutará mi solicitud. Aquí hay dos ejemplos de mi código y el resultado que obtengo en la vista de texto:
public void changText(View view) {
TextView textv = (TextView)findViewById(R.id.textview1);
textv.setText("Text Has Been Changed");
BufferedReader in = null;
String data = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
URI website = new URI("http://alanhardin.comyr.com/matt24/matt28.php");
request.setURI(website);
HttpResponse response = httpclient.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
textv.append(" Connected ");
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
El TextView lee: El texto ha sido cambiado
public void changText(View view) {
TextView textv = (TextView)findViewById(R.id.textview1);
textv.setText("Text Has Been Changed");
BufferedReader in = null;
String data = null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet();
URI website = new URI("http://alanhardin.comyr.com/matt24/matt28.php");
request.setURI(website);
//HttpResponse response = httpclient.execute(request);
//in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
textv.append(" Connected ");
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
El TextView lee: El texto ha sido cambiado conectado
En este manifiesto tengo:
<uses-permission android:name="android.permission.INTERNET" />
En el registro de errores, obtengo lo siguiente: Error en la conexión http android.os.NetworkOnMainThreadException
Cualquier ayuda sería apreciada.