json 获取不支持的媒体类型错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30511911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting not supported media type error
提问by Qasim
Hi i am using Rest client i.e Postman to send the REST request but getting error :
嗨,我正在使用 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"
}
My controller is :
我的控制器是:
@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);
}
I am sending the request as shown in picture via REST client.
我正在通过 REST 客户端发送如图所示的请求。


回答by kjsebastian
Change your Content-Typein Postman to application/json. Click on the Headersbutton to do so.
将您Content-Type的 Postman更改为application/json. 单击标题按钮执行此操作。
Also you are not producing json in the method. Remove the produces="application/json"from the annotation
您也没有在该方法中生成 json。produces="application/json"从注释中删除

