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

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属性解决乱码问题。

posted @ 2018-07-12 09:55  梦尽落花  阅读(361)  评论(0编辑  收藏  举报