Answer the question
In order to leave comments, you need to log in
Android. How to get data from the site?
Trouble... I can't make an elementary GET request to the page .
I get an error with the text null
Here is the code:
public class LogicClass {
final String URL_STRING = "http://kofon.esy.es/test.php";
public String getData() {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(URL_STRING);
String text; // возвращаем эту строку
try {
client.execute(get); // вот тут, выполнение бросает ошибку
text = "ok"; // очень бы хотел дойти до этого места!
} catch (Exception e){
text = "Error: " + e.getMessage();
}
return text;
}
}
/* Вызов в MainActivity*/
String text = _logic.getData();
Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
Answer the question
In order to leave comments, you need to log in
You need to look aside e.printStackTrace();
there is a lot of useful information for the developer and a lot of unnecessary information for the user
ps DefaultHttpClient and so on. Apache tails are deprecated and will be removed soon (if not ALREADY), use urlConnection or HttpUrlConnection or any volley, okhttp..
Here are the logs, they don’t tell me anything personally (I don’t have much experience):
https://hsto.org/files/900/ede/b10/900edeb10cbc4e7...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question