[英]Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
@PostMapping public UserResponse createUser(@RequestBody UserRequest userDetail) { @PostMapping public UserResponse createUser(@RequestBody UserRequest userDetail) {
UserResponse returnValue = new UserResponse();
UserDto userDto = new UserDto();
BeanUtils.copyProperties(userDetail, userDto);
UserDto storedData = userService.createUser(userDto);
BeanUtils.copyProperties(storedData, returnValue);
return returnValue;
}
this is the code I am getting this error这是我收到此错误的代码
{
"timestamp": "2020-05-13T12:24:04.866+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "/users"
} }
I have tried a lot of different ways still not getting the solution This is the image from the postman image from postman我尝试了很多不同的方法仍然没有得到解决方案这是来自 postman 的图像来自 postman的图像
That because your service is only accepting application/json content type.那是因为您的服务仅接受 application/json 内容类型。 If you want to accepting application/x-www-form-urlencoded you can add consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE inside @PostMapping annotation如果您想接受 application/x-www-form-urlencoded 您可以在 @PostMapping 注释中添加 consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE
bellow is sample of service that accept application/json and give application/json response.下面是接受 application/json 并给出 application/json 响应的服务示例。
@PostMapping(path = "/v1/agent/create", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ApiResponseWrapperDto createAgent(@RequestBody ApiRequestWrapperDto request) throws Exception {
return this.agentManagementApiHandler.createAgent(request);
}
Hope this solve your problem.希望这能解决您的问题。
Thanks谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.