【问题标题】:Spring, Angular.js 415 Unsupported Media Type ErrorSpring,Angular.js 415 不支持的媒体类型错误
【发布时间】: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


【解决方案1】:

我通过删除 consumes='application/json' 解决了这个问题。

【讨论】:

    猜你喜欢
    • 2016-09-10
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 2018-07-25
    • 2016-09-09
    • 2015-02-25
    • 1970-01-01
    相关资源
    最近更新 更多