简体   繁体   中英

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

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

Are you using Postman to fire the request? you might want to check these settings

在此处输入图像描述

Edit. Add another image for troubleshooting

在此处输入图像描述

That because your service is only accepting application/json content type. If you want to accepting application/x-www-form-urlencoded you can add consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE inside @PostMapping annotation

bellow is sample of service that accept application/json and give application/json response.

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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