在Spring中处理不受支持的媒体类型

问题描述 投票:0回答:1

我目前正在使用Spring框架构建一个简单的REST服务。但是在使用Postman进行测试时,我遇到了以下问题:Click to view image

我不知道如何使Spring识别接收到的Content-Type标头实际上与application/x-www-form-urlencoded相匹配,这受支持。

更新:

我目前在localhost的嵌入式Tomcat服务器上运行我的应用程序。

我的端点简要包括:

  1. POST:/api/users-用于创建新用户
  2. 获取:/api/users-用于列出用户
  3. 获取:/api/users/{id}-用于通过其ID检索用户

POST端点的请求正文:

"email":"<your-email>",
"password:"<your-password>"

更新2:

My Endpoint image

spring rest http-headers mime-types
1个回答
0
投票

尝试一下:

@PostMapping(path = "/api/users",consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
public ResponseEntity<String> createUser(@RequestBody User user)
© www.soinside.com 2019 - 2024. All rights reserved.