Hi I am woring for a Quiz App, so I need to call post rest services(json),below one is my sample code which is not working
I need to pass 3 thing as parameter 1-userid, 2-List questionids and 3- List answerIds. My Question is how to pass List Object not String or Json String here-
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userid", "121213"));
nameValuePairs.add(new BasicNameValuePair("questionsids", listobj);
nameValuePairs.add(new BasicNameValuePair("answerIds", listObj));
HttpClient httpclient=new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setHeader(HTTP.CONTENT_TYPE,"application/x-www-form-urlencoded;charset=UTF-8");
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Is There any other way to call the post rest service.How to resolve above one?
Thanks Ranjan.
use for loop and add with same key.
Like this:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); for (ModelAssignee assignee : assignmentChips.getAssignees()) { nameValuePairs.add(new BasicNameValuePair("AssignedToIds", String.valueOf(assignee.Id))); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.