Answer the question
In order to leave comments, you need to log in
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();
}
Answer the question
In order to leave comments, you need to log in
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
Use requests using HttpURLConnection exclusively through AsyncTask.
Example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question