码迷,mamicode.com
首页 > 其他好文 > 详细

浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

时间:2018-07-12 13:31:25      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:jar   解决   方式   属性   注解   img   配置文件   size   cte   

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

 

 

 

技术分享图片

 

网上关于这个问题有很多说法,有的说spring mvc版本问题的,有说jackson jar包问题问题的,试了下都不可以,

这里的解决方法参考:

https://www.cnblogs.com/1315925303zxz/p/7404299.html

https://blog.csdn.net/lkwan123/article/details/73385025

我这里报错的原因是因为复制粘贴了一个 produces = "text/html;charset=UTF-8"

技术分享图片

这个是解决http请求响应的乱码问题,在@RequestMapping注解上使用produces属性来快速解决,实际上工程配置里面已经加了配置解决乱码问题。请求的后缀.html,会欺骗浏览器当做一个静态网页来解析,是一个简单的SEO优化。一般来说是没问题的。但是这里我们使用了@ResponseBody,返回数据后缀是,.json,但是我们的映射器后缀又是.html.最后浏览器收到数据不知该以哪种类型数据来进行解析,所以就会报406状态码。

 

解决这种问题的方式有俩种:

一是直接将produces属性去掉,万一出现了乱码则在配置文件或编解码的方式处理,

二是先将对象转成json数据,然后可以使用produces属性解决乱码问题。

技术分享图片

浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers

标签:jar   解决   方式   属性   注解   img   配置文件   size   cte   

原文地址:https://www.cnblogs.com/mengjinluohua/p/9297985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!