Android HTTP Get
Я смотрю несколько постов на форуме, и я не могу найти ответ на мою проблему. Я пытаюсь получить ответ из файла php. PHP-файл работает. Проблема в том, что приложение для Android не выполнит мой запрос. Вот два примера моего кода и результат, который я получаю в текстовом виде:
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());
}
}
TextView читает: текст был изменен
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());
}
}
TextView читает: текст был изменен подключен
В этом манифесте у меня есть:
В журнале ошибок я получаю следующее: Ошибка в http-соединении android.os.NetworkOnMainThreadException
Любая помощь будет оценена.