SpringBoot 出现 Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
Question1:
当前端请求的Content-Type是Json时,可以用@RequestBody这个注解来解决。@RequestParam 底层是通过request.getParameter方式获得参数的,换句话说,@RequestParam 和request.getParameter是同一玩意儿。因为使用request.getParameter()方式获取参数,可以处理get 方式中queryString的值,也可以处理post方式中 body data的值。所以,@RequestParam可以处理get 方式中queryString的值,也可以处理post方式中 body data的值。@RequestParam用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容,提交方式GET、POST。
Question2:
如果Content-Type设置为“application/x-www-form-urlencoded;charset=UTF-8”无论是POST请求还是GET请求都是可以通过这种方式成功获取参数,但是如果前端POST请求中的body是Json对象的话,会报上述错误。
请求中传JSON时设置的Content-Type 如果是application/json或者text/json时,JAVA中request.getParameter("")怎么也接收不到数据。这是因为,Tomcat的HttpServletRequest类的实现类为org.apache.catalina.connector.Request(实际上是org.apache.coyote.Request在作怪)。
@RequestBody接受的是一个json对象的字符串,而不是Json对象,在请求时往往都是Json对象,用JSON.stringify(data)的方式就能将对象变成json字符串。
end:
前端请求传Json对象则后端使用@RequestParam;
前端请求传Json对象的字符串则后端使用@RequestBody。
SpringBoot 出现 Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported相关推荐
- Springboot 报错Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
SpringBoot错误解决 1.错误展示 2021-03-23 12:20:02.805 ERROR org.springframework.web.HttpMediaTypeNotSupporte ...
- Spring Boot——[Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]解决方案
问题描述 2020-02-13 19:32:04.322 WARN 109508 --- [p-nio-80-exec-4] .m.m.a.ExceptionHandlerExceptionResol ...
- Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
强烈推荐一个大神的人工智能的教程:http://www.captainbed.net/zhanghan [前言] 最近在用restTemplate进行一次http请求时发现了报错(Error whil ...
- “Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“解决方法
项目接口返回 code: 500 data: null message: "Content type 'application/x-www-form-urlencoded;charset=U ...
- jmeter报“msg“:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“的解决方法
jmeter报"msg":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supp ...
- Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported
问题描述: 我写了一个接口,这个接口参数是这样的 @ResponseBody @RequestMapping(value = "importData", method = Requ ...
- 请求状态为200,前端报系统出错,后端日志报“Content type ‘application/octet-stream‘not supported“错误
请求后端出现"Content type 'application/octet-stream'not supported"错误 错误描述: Content type 'applica ...
- 苹果微信推送服务器错误,接入WxPusher微信推送服务出现错误:Content type application/x...
背景 使用WxPusher微信推送服务 ,可以及时的将服务的一些运行异常信息,发送到自己的微信上,方便了解服务的运行状态(PS:这个服务是免费的). 你可以在这里看到WxPusher微信推送服务的接入 ...
- HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n
问题如下: Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'applicatio ...
最新文章
- HashSet、TreeSet和LinkedHashSet
- jsfl 改变舞台宽高
- 计算机组成原理--主存储器
- 设计模式 C++工厂方法模式
- Jscript 控制程序的流程
- ISTQB 软件测试资质认证
- 国开大学计算机应用实操题作业如何上传,国开电大18秋《计算机应用基础》形考任务作业.doc...
- 计算机病毒属于源程序吗,计算机病毒是否是源程序吗
- 利用echarts做堆积折线图
- 龙格库塔方法在实际生活中的应用(数值计算Java)
- 面试题53:vue数据的双向绑定原理(如何实现vue的双向绑定)
- matlab if嵌套函数,MATLAB嵌套函数的应用
- phpstorm9中文输入法不好用的解决方案
- 为什么说学web前端是IT互联网时代的不二选择?
- Rhombus 使用 Wolfspeed SiC 加快电动汽车充电速度
- 纯js版本网页连连看原理分析和实现
- java 指定垃g1圾收集_【译】Java 14 Hotspot 虚拟机垃圾回收调优指南
- 杰理之GPIO汇总【篇】
- 组织QClub大连站活动的感受
- GOF设计模式之代理模式(结构型代理模式)
热门文章
- 计算机编程语言及Java
- Linux之kickstart全自动安装
- [tips] 1.2 优麒麟ubuntu 20安装ROS2 Foxy版本
- 计算机内部线有,电脑主机内部有几根线?分别叫什么?
- Thiago2(TPO AI.ROSTO):集成式AI换脸软件(Autodesk Flame)
- 如何管理自己的时间?
- 基于SSM+vue的前后端分离小项目(用户后台管理系统的实现)
- java 对图片解码_java对图片的转码和解码 实用
- VHDL语言Process
- 学阿里中台,80%的人只学到了皮毛!揭秘阿里中台的12个架构思维和原则