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

33

你好,我正在使用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客户端按照图片所示发送请求。

在这里输入图片描述

3个回答

64

在Postman中将Content-Type更改为application/json,点击Headers按钮进行操作。

同时,在此方法中您没有生成json。请从注释中删除produces="application/json"


1
你的意思是更改“Accept”头。 - ci_

13

我曾经遇到过相同的问题,但是用了另一种方法解决了它。

较新版本的Postman在"Body"部分有选项。 如果选择“raw”,则会出现一个下拉菜单,“JSON(application/json)”可用。

POST Body raw : JSON


5
在Postman应用程序中的Headers下,将Key设置为Content-Type,值设置为application\json。请参考以下截图: enter image description here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接