HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n

问题如下:

Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]

415:
HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第1张图片

 原因:

打开network查看Request Headers 中的Content-Type:

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第2张图片

由于我们需要传入的数据为json格式,所以需要修改此地方。

解决办法:

加入一个

 headers:{

                            "Content-Type":"application/json"

                        },

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第3张图片

 添加后:

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第4张图片

自然程序也就能够成功运行了:

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第5张图片

 代码参考:

前端:

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第6张图片

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第7张图片

 后端:

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第8张图片

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第9张图片

ControllerException:将错误信息返回给前台

HttpMediaTypeNotSupportedException: Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ n_第10张图片

你可能感兴趣的:(java,前端,vue,spring,boot)