Spring 3 MVC JSON REST response based on header
I'm trying to get Spring to return JSON strings from a RESTful service when someone calls it accepting JSON. I'm following some of the examples here. The method looks as follows:
@SuppressWarnings("unchecked")
@RequestMapping(value = "/**", method = RequestMethod.GET, headers="Accept=application/json")
@ResponseBody
public String someMethod(@RequestBody String url, HttpServletRequest request) {
....
}
When I curl
this method, I'm getting a Error 415 Unsupported Media Type
curl -i -H "Accept:application/json"
http://localhost:8080/the/url/here
HTTP/1.1 415 Unsupported Media Type
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-开发者_运维百科store
Content-Length: 1429
Server: Jetty(8.0.0.M2)
<html>
...
Any help would be appreciated. Thank you.
415 means the media type of the request entity isn't supported. I'm guessing that since you sent no entity at all but the controller specifies an @RequestBody, it's actually complaining that you didn't send any content where content is required.
精彩评论