Android HttpPost: how to get the result
Posted
by Sumit M Asok
on Stack Overflow
See other posts from Stack Overflow
or by Sumit M Asok
Published on 2010-02-24T04:12:31Z
Indexed on
2010/03/29
10:53 UTC
Read the original article
Hit count: 484
I have been trying long to send an HttpPost request and retrieve response but even though I was able to make a connection I don't yet get how to get the string message which is returned by the request-response
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.myurl.com/app/page.php");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("type", "20"));
nameValuePairs.add(new BasicNameValuePair("mob", "919895865899"));
nameValuePairs.add(new BasicNameValuePair("pack", "0"));
nameValuePairs.add(new BasicNameValuePair("exchk", "1"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.d("myapp", "works till here. 2");
try {
HttpResponse response = httpclient.execute(httppost);
Log.d("myapp", "response " + response.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
I'm sorry, I sound very naive because I'm new to java. Please help me.
© Stack Overflow or respective owner