Я использую AsyncTask для подключения к серверу. Я следовал за сообщением: Http Получить с помощью Android HttpURLConnection
, но я всегда получаю IOException (return xxx -33). Что я делаю неправильно? при просмотре журнала apache я вижу, что запрос POST не был получен.
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;
}