spring - 在 Spring 中处理不支持的媒体类型
问题描述
我目前正在使用 Spring 框架构建一个简单的 REST 服务。但是在使用 Postman 进行测试时,我遇到了以下问题: 点击查看图片
我想知道如何让 Spring 识别收到的 Content-Type 标头实际上与application/x-www-form-urlencoded
受支持的 .
更新:
我目前正在localhost
使用嵌入式 Tomcat 服务器运行我的应用程序。
我的终点简要包括:
- POST:
/api/users
- 用于创建新用户 - GET:
/api/users
- 用于列出用户 - GET:
/api/users/{id}
- 用于通过 id 检索用户
POST 端点的请求正文:
"email":"<your-email>",
"password:"<your-password>"
更新2:
解决方案
尝试这个:
@PostMapping(path = "/api/users",consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
public ResponseEntity<String> createUser(@RequestBody User user)
推荐阅读
- erlang - 我怎样才能摆脱 Elixir 中的 Enum.reduce
- java - Spring Cloud - Feign - 无法实例化 [feign.Retryer]
- sql - 在一次点击数据库中选择所有多对多记录以及父表
- c# - CacheManager 与 inproc 和 Redis 一起处理,因为背板未同步
- javascript - Javascript 删除“字符串”中的空格
- debugging - 在本地目录中找不到 .gdbinit 文件
- postgresql - 从历史数据中查询当前数据
- python - pandas groupby 多级标题
- swift - 应用内购买 - 如何仅恢复一种产品
- docker - 如何在没有 root 身份的情况下连接到远程 docker 守护进程?