获得不支持的媒体类型错误

Qas*_*sim 21 rest json spring-boot

嗨我正在使用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"
}
Run Code Online (Sandbox Code Playgroud)

我的控制器是:

@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);
    }
Run Code Online (Sandbox Code Playgroud)

我通过REST客户端发送请求,如图所示.

在此输入图像描述

kjs*_*ian 48

Content-Type邮差变成application/json.单击" 标题"按钮即可.

你也没有在方法中生成json.produces="application/json"从注释中删除


小智 6

我有同样的问题,并以不同的方式解决它.

较新版本的邮递员在"正文"部分中有选项.如果选择"raw",则会出现"JSON(application/json)"工作的下拉列表.

POST Body raw:JSON


小智 5

在 Postman 应用程序的 headers 下,键入 Key asContent-Type并将值设置为application\json

在此输入图像描述