Take the 2-minute tour ×

I wish to append a List<Beans> in a HTTP Post request.

While making use of Apache HTTPClient, I am unable to do the same.

This is what I wish to do:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

nameValuePairs.add(new BasicNameValuePair("dailySalesList",beanList));

post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

However, the BasicNameValuePair seems to take only 2 Strings as argument. I wish to utilize it so that I can use a String - for identification and Object - to pass a List. Basically a functionality similar to using a Map.

Any pointers on how it can be done using Apache HTTPClient ?

share|improve this question
add comment

2 Answers

The NameValuePair in this context is intended for sending simple text parameters as queries in the URL (the ?foo=1&bar=2 parameters you see sometimes). The best way to send something more complex like a list is to serialize it in an interchange format like XML or JSON and then send it as the request body.

share|improve this answer
add comment
up vote 0 down vote accepted

Thanks Kiyura for pointing me in the right direction, to make use of JSON.

I made use of the GSON java library for conversion from List to JSON representation.

Its a pretty library in case you want to use JSON without manually converting Generic Types.

The gson doc is also a good reference.

share|improve this answer
add comment

Your Answer


