I am sending a POST request to a Server from my Android Application. The Server is developed using Spring Framework. The request is received by the server but the parameter that I was sending is null/empty (shown in the log).
The code used to send POST request is:
DefaultHttpClient hc=new DefaultHttpClient();
ResponseHandler <String> res=new BasicResponseHandler();
String postMessage = "json String";
HttpPost postMethod=new HttpPost("http://ip:port/event/eventlogs/logs");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("json", postMessage));
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
hc.execute(postMethod,res);
I have also tried to set HttpParams as follows but it has also failed:
HttpParams params = new BasicHttpParams();
params.setParameter("json", postMessage);
postMethod.setParams(params);
The code on Server side that received this request is:
@RequestMapping(value = "/eventlogs/logs", method = RequestMethod.POST)
public String logs(@ModelAttribute("json") String json) {
logger.debug("Received POST request:" + json);
return null;
}
The Logger message that I am logging shows:
Received POST request:
Any ideas what I am missing here ?
I have used the RequestParam Annotation and it works for me. Now the code on server is as follows: