I am using a URLConnection object to send data from my android client to the server.
URL url = new URL("http://10.0.2.2:8080/hello"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream()); String s="check"+","+susername; out.writeObject(s); out.flush(); out.close();
But I have seen many Android programs sending data using httppost as follows.
HttpClient client=new DefaultHttpClient(); HttpPost httpPost=new HttpPost(LOGIN_ADDRESS); List pairs=new ArrayList(); String strUsername=username.getText().toString(); String strPassword=password.getText().toString(); pairs.add(new BasicNameValuePair("username", strUsername)); pairs.add(new BasicNameValuePair("password", strPassword)); httpPost.setEntity(new UrlEncodedFormEntity(pairs)); HttpResponse response= client.execute(httpPost);
please explain the difference between the two. How do you get the data in the latter case in the servlet. give a brief description of this HttpPost. On the Internet, all I find is code. PLS gives a step-by-step explanation of HttpPost and its methods and how they should receive data in the servlet. Links will be fine.
source share