Android : Android HttpPost Send ArrayList

on Monday, August 11, 2014


i try to send arraylists with httpPost.i searched and learn how to can send httpPost.i wrote code with can send simple httpPost,but i do not know how i can send Arraylist. this is my code



public static void SendHttpPost(String Url,String method,ArrayList<String> args,int id)
{

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Url);

try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("method", method));
nameValuePairs.add(new BasicNameValuePair("args", args.ad));//here i would send arraylist
nameValuePairs.add(new BasicNameValuePair("id", String.valueOf(id)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
System.out.println(response);

} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}


i would to send like this Arralist



{"objectType" : 0,"languageISOCode" : "eng"}


if anyone knows solution please help me


0 comments:

Post a Comment