I am aware that here in stackoverflow are plenty of questions related to mine, but I cant understand 100% to their explanations of how to send and receive data from a web server using httpUrlConnection.
I used to do it with httpClient and I used the following code:
Here is my class httpClient:
public class httpHandler {
public String post(String posturl){
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(posturl);
HttpResponse resp = httpclient.execute(httppost);
HttpEntity ent = resp.getEntity();
String text = EntityUtils.toString(ent);
return text;
}catch(Exception e){
return "error";
}
}
}
and then I used to send and receive the data like this:
String responseLikeCuenta = variablesApp.handler.post(url);
It was as simple as that but now with the httpUrlConnection I cant understand how to do it, and when I read the tutorials I see lots of code just for sending one string. Is there a simpler way to do it?
Is there a way to do it inside the onCreate?