In my case I had to create JSON something like:
{ fan: { email : 'foo@bar.com' } }
which equates to the HTML form input:
<input name="fan[email]" type="text"/>
To POST in Android. You can use something like this code.
public static String makeRequest(String path, Mapparams)
throws Exception {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(path);
Iterator iter = params.entrySet().iterator();
JSONObject holder = new JSONObject();
while(iter.hasNext()) {
Map.Entry pairs = (Map.Entry)iter.next();
String key = (String)pairs.getKey();
Map m = (Map)pairs.getValue();
JSONObject data = new JSONObject();
Iterator iter2 = m.entrySet().iterator();
while(iter2.hasNext()) {
Map.Entry pairs2 = (Map.Entry)iter2.next();
data.put((String)pairs2.getKey(), (String)pairs2.getValue());
}
holder.put(key, data);
}
StringEntity se = new StringEntity(holder.toString());
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
ResponseHandlerresponseHandler = new BasicResponseHandler();
response = httpclient.execute(httpost, responseHandler);
}