您好,我正在使用 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"
}
我的 Controller 是:
@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 客户端发送如图所示的请求。
最佳答案
将 Postman 中的 Content-Type
更改为 application/json
。单击标题按钮即可执行此操作。
此外,您没有在该方法中生成 json。从注释中删除 products="application/json"
关于json - 收到不支持的媒体类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30511911/