Search code examples
javaandroidservletssend

Sending data to servlet from android


I am trying to send data from android emulator to servlet running on localhost, I have following code, but its not sending data to servlet. I have also tried my ip "192.168.2.15:8080" instead of "10.0.2.2:8080" but result is same, could anyone please tell me where I am wrong?

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
    "http://10.0.2.2:8080/Interactive_ICS_Web/datareciever");

try {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("username", "naveed"));
    nameValuePairs.add(new BasicNameValuePair("password", "12345"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
} catch (IOException e) {
    // TODO Auto-generated catch block
}

Solution

  • Problem solved, it was my stupidness. I was using httppost in android code, and trying to receive in doGet() on servlet