【发布时间】:2021-10-12 11:09:33
【问题描述】:
这个简单的请求遇到了 415 Unsupported Media Type 错误。
http://localhost:8080/semantic/api/getLastfmGraph/1
这是我的控制器代码:
@RequestMapping(value = "/getLastfmGraph/{userId}", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public
@ResponseBody
Object getLastfmGraph(@PathVariable Long userId) throws Exception {
User user = semanticGraphDao.findUserById(userId);
List<Node> nodes = lastfm.topArtistsByUser(user.getLastfmUsername());
List<Link> links = new ArrayList<>();
for (Node n : nodes) {
for (Node n2 : nodes) {
if(!StringUtils.equals(n.getName(),n2.getName()))
links.add(new Link(n, n2, 1.0));
}
}
return new Graph(nodes,links);
}
【问题讨论】:
-
API 期望
Content-Type标头的值为application/json -
我通过删除 consumes='application/json' 解决了这个问题
标签: angular spring rest http-status-code-415