相关文章推荐
慈祥的紫菜汤  ·  <col>:表格欄元素 - ...·  4 月前    · 
坚韧的竹笋  ·  protobuf_MODULE_COMPAT ...·  1 年前    · 
憨厚的烈酒  ·  C#中 ...·  2 年前    · 

org.springframework.http.InvalidMediaTypeException: Invalid mime type "application/x-www-form-urlencoded charset=UTF-8":

将get请求改为post请求,参数改为body之后,前端调用后台系统报错,错误日记如下所示

org.springframework.http.InvalidMediaTypeException: Invalid mime type “application/x-www-form-urlencoded charset=UTF-8”: Invalid token character ’ ’ in token “x-www-form-urlencoded charset=UTF-8”
at org.springframework.http.MediaType.parseMediaType(MediaType.java:371) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:717) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.http.server.ServletServerHttpRequest.getHeaders(ServletServerHttpRequest.java:115) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:807) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.cors.DefaultCorsProcessor.processRequest(DefaultCorsProcessor.java:71) ~[spring-web-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMapping$CorsInterceptor.preHandle(AbstractHandlerMapping.java:503) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:134) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:954) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269) [catalina.jar:9.0.0.M1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184) [catalina.jar:9.0.0.M1]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-websocket.jar:9.0.0.M1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:217) [catalina.jar:9.0.0.M1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184) [catalina.jar:9.0.0.M1]

产生这个错误的原因是请求改为post和body方式之后,前端请求的contentType没有做相应的改动还是保持原来的表单提交方式。

前端请求将contentType属性设置为:application/json即可。

org.springframework.http.InvalidMediaTypeException: Invalid mime type "application/x-www-form-urlencoded charset=UTF-8":问题描述问题原因解决方案问题描述将get请求改为post请求,参数改为body之后,前端调用后台系统报错,错误日记如下所示org.springframe...
关于出现“Content type application /x- www - form - urlencode d;charset=UTF-8‘ not supported“问题如何解决
在公司开发项目中,当前端传来参数时,前端却报错,报错信息显示”Content type application /x- www - form - urlencode d;charset=UTF-8’ not supported“ 此问题的原因是因为前后端数据交互出现json数据类型不符合 json 分为两种类型; (1) json 对象类型,即前端定义的Content type application /x- www - form - urlencode d等 (2) json字符串类型,即前端定义的Conten org . springframework . http . Invalid Media Type Exception : Invalid mime type " application ": does not contain '/' at org . springframework . http . Media Type .parse Media Type ( Media Type .java:586) at org . springframework . http . Http Headers.getContent Type ( Http Headers.java