A
A
Allsir2020-05-28 19:17:57
Java
Allsir, 2020-05-28 19:17:57

Why Android Java GET request is not sent?

I'm trying to send data to the server (so that it adds them to the MySQL database) from an Android application using a GET request. There is a php file on the server that processes this request, it is definitely working, if you just type the request into the address bar of the browser, then everything that is needed is added to the database.

I'm trying to send as follows, sending occurs by clicking on the button:

public void SendToBase() {
new Thread(new Runnable() {
public void run() {
try {
URL url = new URL(" mysite.ru/test.php?test=Hi&testtest=305 ");
HttpURLConnection connection = (HttpURLConnection )url.openConnection();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
MyTextView.setText("Sent");
} else {
MyTextView.setText("Error");
}
} catch (Exception e) {
MyTextView.setText("Exception");
e.printStackTrace();
}
}
}).start();
}

public void MyButton(View v) throws IOException {
SendToBase();
}


As a result, an exception is triggered, judging by the server logs, the request simply does not even come there. The application has permission to use the Internet. Tell me what could be the problem

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lyoshik, 2020-05-28
@Allsir

So lay out the text of the exception.
Perhaps the problem is in the url, try changing it to :
http://mysite.ru/test.php?test=Hi&testtest=305

A
Alexey, 2020-05-28
@fapsi

Use requests using HttpURLConnection exclusively through AsyncTask.
Example

S
szanislo, 2020-05-28
@szanislo

I can assume that you need to set the permission in the manifest file

<uses-permission android:name="android.permission.INTERNET" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question