Y
Y
Ytsu Ytsuevich2015-06-15 16:30:28
Android
Ytsu Ytsuevich, 2015-06-15 16:30:28

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();

And I see a failure:
8ec00bc225934ea8a6698b60f020cd6e.PNG
Do I need to add something to the manifest?
Now added: uses-permission android:name="ANDROID.PERMISSION.INTERNET" Newbie
in android!
And the page just shows the passed parameters:
// PHP
print_r($_GET);
print_r($_POST);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2015-06-15
@kofon

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..

Y
Ytsu Ytsuevich, 2015-06-15
@kofon

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...
c63621101d1246798ea923a572bf34fb.PNG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question