首页 > 其他 > 详细

浏览器报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 11:25:05      阅读:628      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!