【问题标题】:Getting not supported media type error获取不支持的媒体类型错误
【发布时间】:2015-08-11 06:39:14
【问题描述】:

您好,我正在使用 Rest 客户端,即 Postman 发送 REST 请求但收到错误:

{
    "timestamp": 1432829209385,
    "status": 415,
    "error": "Unsupported Media Type",
    "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
    "message": "Content type 'text/plain;charset=UTF-8' not supported",
    "path": "/api/v1/user"
}

我的控制器是:

@RequestMapping(value = "/user", method = RequestMethod.PUT, produces = "application/json")
    public Map<String,Object> updateUser(@RequestBody @Valid User user) {
//      userService.updateUser(user);
        return ResponseHandler.generateResponse("", HttpStatus.ACCEPTED, false, null);
    }

我正在通过 REST 客户端发送如图所示的请求。

【问题讨论】:

    标签: json rest spring-boot


    【解决方案1】:

    在 Postman 应用程序的标题下,键入 Content-Type 的键并将值设置为 application\json

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,并以不同的方式解决了它。

      较新版本的 Postman 在“正文”部分提供选项。如果选择“raw”,则有一个下拉菜单,其中“JSON (application/json)”可以工作。

      【讨论】:

        【解决方案3】:

        将 Postman 中的 Content-Type 更改为 application/json。单击标题按钮即可。

        您也没有在该方法中生成 json。从注解中删除produces="application/json"

        【讨论】:

        • 您的意思是,更改Accept 标头。
        猜你喜欢
        • 1970-01-01
        • 2020-05-12
        • 2014-11-11
        • 2018-10-13
        • 2018-07-25
        • 2016-09-09
        • 2017-08-28
        • 2023-02-02
        • 2015-06-18
        相关资源
        最近更新 更多