I had this working a few weeks ago, but it stopped working after making a few changes to my webservice
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody String addComplaint(@RequestBody Complaint complaint) {
......
}
curl -i -H "content-type: application/json" -X POST -d '{"var1":"data1","var2":"data2"}' http://server:8080/api/complaint/add
Below is what I get
HTTP/1.1 415 Unsupported Media Type
Pragma: no-cache
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1408
Server: Jetty(8.1.8.v20121106)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 415 Unsupported Media Type</title>
</head>
<body><h2>HTTP ERROR 415</h2>
<p>Problem accessing /api/complaint/add. Reason:
<pre> Unsupported Media Type</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
</body>
</html>
I had this error sometime back and I solved it by setting headers i.e httpPost.setHeader("accept", "application/json"), httpPost.setHeader("content-type", "application/json"); but after making changes to my webservice, it failed to work again. The curl command gave me the output above. Any help will be highly appreciated