关于出现“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“问题如何解决

关于出现“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“问题如何解决

所遇问题
在公司开发项目中,当前端传来参数时,前端却报错,报错信息显示”Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported“

原因
此问题的原因是因为前后端数据交互出现json数据类型不符合
json 分为两种类型;
(1) json 对象类型,即前端定义的Content type 为 application/x-www-form-urlencoded等
(2) json字符串类型,即前端定义的Content type 为 application/json

解决办法
前端传输的json数据类型和后端使用的注解应有正确的对应关系
当前端请求传Json对象则后端使用@RequestParam注解;
当前端请求传Json对象的字符串则后端使用@RequestBody注解。

猜你喜欢

转载自blog.csdn.net/weixin_44188105/article/details/131687822
今日推荐