I'm using AsyncTask to connect to a server. I followed the post: Http Get using Android HttpURLConnection
but I always get an IOException (return xxx -33). What am I doing wrong? going to see the apache log I see that the POST request has never been received.
public abstract class SenderHttp extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
Log.i("TAG", params[0]);
Log.i("TAG", params[1]);
String data = "";
HttpURLConnection httpURLConnection = null;
int responseCode=-33;
try {
httpURLConnection = (HttpURLConnection) new URL(params[0]).openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setConnectTimeout(10000);
httpURLConnection.setReadTimeout(10000);
httpURLConnection.connect();
responseCode = httpURLConnection.getResponseCode();
} catch (IOException e) {
e.printStackTrace();
return "xxx" + " "+ responseCode;
}
return " "+ responseCode;
}