Вот код для удара по сервлету и отправки данных на сервер.
boolean hitServlet(final Context context, final String data1,final String data2) {
String serverUrl = SERVER_URL + "/YourSevletName";
Map<String, String> params = new HashMap<String, String>();
params.put("data1", data1);
params.put("data2" data2)
long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000);
// As the server might be down, we will retry it a couple
// times.
for (int i = 1; i <= MAX_ATTEMPTS; i++) {
try {
post(serverUrl, params);
return true;
} catch (IOException e) {
// Here we are simplifying and retrying on any error; in a real
// application, it should retry only on unrecoverable errors
// (like HTTP error code 503).
Log.e(TAG, "Failed " + i, e);
if (i == MAX_ATTEMPTS) {
break;
}
try {
Log.d(TAG, "Sleeping for " + backoff + " ms before retry");
Thread.sleep(backoff);
} catch (InterruptedException e1) {
// Activity finished before we complete - exit.
Log.d(TAG, "Thread interrupted: abort remaining retries!");
Thread.currentThread().interrupt();
return false;
}
// increase backoff exponentially
backoff *= 2;
}
}
return false;
}