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 String SendHttpPost(String Url,String method,HashMap<String,String> args,int id)
{
HttpResponse response = null;
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.put("objectType", String.valueOf(0))));
nameValuePairs.add(new BasicNameValuePair("args", args.put("languageISOCode", "eng")));
nameValuePairs.add(new BasicNameValuePair("id", String.valueOf(id)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response= httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch blockF
} catch (IOException e) {
// TODO Auto-generated catch block
}
return String.valueOf(response);
}
I would to send like this Arralist
:
{"objectType" : 0,"languageISOCode" : "eng"}
If anyone knows solution, please help me.