繁体   English   中英

内容类型 'application/x-www-form-urlencoded;charset=UTF-8' 不支持

[英]Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported

@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;
}

这是我收到此错误的代码

{
"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"

}

我尝试了很多不同的方法仍然没有得到解决方案这是来自 postman 的图像来自 postman的图像

您是否使用 Postman 来触发请求? 您可能需要检查这些设置

在此处输入图像描述

编辑。 添加另一个图像以进行故障排除

在此处输入图像描述

那是因为您的服务仅接受 application/json 内容类型。 如果您想接受 application/x-www-form-urlencoded 您可以在 @PostMapping 注释中添加 consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE

下面是接受 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);
}

希望这能解决您的问题。

谢谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM