0

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

Henry
  • 91
  • 1
  • 5

1 Answers1

0

Your request might be missing an accept header try this :

curl -i -H "content-type: application/json" -H "Accept: application/json" -X POST -d '{"var1":"data1","var2":"data2"}' http://server:8080/api/complaint/add
jpprade
  • 3,497
  • 3
  • 45
  • 58
  • error persists. I even tried following directions from this link http://stackoverflow.com/questions/11291933/requestbody-and-reponsebody-spring – Henry Oct 23 '14 at 10:28