简体   繁体   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) { @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的图像

Are you using Postman to fire the request?您是否使用 Postman 来触发请求? you might want to check these settings您可能需要检查这些设置

在此处输入图像描述

Edit.编辑。 Add another image for troubleshooting添加另一个图像以进行故障排除

在此处输入图像描述

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.

相关问题 Spring Boot - 不支持内容类型“application/x-www-form-urlencoded;charset=UTF-8” - Spring Boot - Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported HttpMediaTypeNotSupportedException:不支持内容类型 'application/x-www-form-urlencoded;charset=UTF-8' - HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported "status":415, "status":"UNSUPPORTED_MEDIA_TYPE","message":"内容类型 'application/x-www-form-urlencoded;charset=UTF-8' 不支持 - "status":415, "status":"UNSUPPORTED_MEDIA_TYPE","message":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported restcontroller和application / x-www-form-urlencoded; charset = UTF-8媒体类型的问题 - Issue with restcontroller and application/x-www-form-urlencoded;charset=UTF-8 media type 如何使用application / x-www-form-urlencoded运行jmeter请求; charset = UTF-8“(像邮差的)设置 - How to run jmeter requests with application/x-www-form-urlencoded; charset=UTF-8" (like postman's) setting 如何获得RESTeasy方法来正确使用UTF-8编码的application / x-www-form-urlencode? - How can I get a RESTeasy method to consume application/x-www-form-urlencoded as UTF-8 correctly? 如何编写控制器类以允许内容类型:application / json和application / x-www-form-urlencoded - How to write controller class to allow content-type: application/json and application/x-www-form-urlencoded Quarkus - 找不到内容类型应用程序/x-www-form-urlencoded 类型的作者 - Quarkus - could not find writer for content-type application/x-www-form-urlencoded type 内容类型为application / x-www-form-urlencoded的Http Put请求在Spring中不起作用 - Http Put request with content type application/x-www-form-urlencoded not working in Spring 更改请求的内容类型以处理使用application / x-www-form-urlencoded发送的XML - Changing Content-Type of the request to process XML sent using application/x-www-form-urlencoded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM