当有人称其接受JSON时,我正试图让Spring从RESTful服务返回JSON字符串。我在这里关注一些例子。该方法如下所示:
@SuppressWarnings("unchecked")
@RequestMapping(value = "/**", method = RequestMethod.GET, headers="Accept=application/json")
@ResponseBody
public String someMethod(@RequestBody String url, HttpServletRequest request) {
....
}
当我curl
这种方法时,我得到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>
...
任何帮助将不胜感激。谢谢。
答案 0 :(得分:3)
415表示不支持请求实体的媒体类型。我猜测,因为除了控制器指定@RequestBody之外你根本没有发送任何实体,它实际上抱怨你没有发送任何需要内容的内容。