I have a simple form and i need to send it to a URL with the parameters.
Let's say I have one parameter called token and I want to send it to example.com/?token=the_token
I don't need to handle or get the output, just send it to this url.
How I can do this? I've been trying for hours to use URLCONNECTION and HTTPURLCONNECTION and nothing worked.
Since I tried many things and nothing worked, I am trying from scratch. This is it:
if (token.isEmpty()) {
getGCMToken();
} else {
//Send the token to example.com/?token=token. The URL will add the token to my database with PHP.
}
Please do not reply with DefaultHttpClient. It is deprecated.
Trying URLConnection():
if (token.isEmpty()) {
getGCMToken();
} else {
//Send the tokeb to example.com/?token=token
URLConnection connection = null;
try {
connection = new URL("mysite.com/send.php?id=my_id").openConnection();
} catch (IOException e) {
e.printStackTrace();
}
connection.setRequestProperty("Accept-Charset", "UTF-8");
try {
InputStream response = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
}