美文网首页
Tomcat :URL 请求向后台传 json 字符串报 400

Tomcat :URL 请求向后台传 json 字符串报 400

作者: 春泥村雨 | 来源:发表于2021-03-26 10:21 被阅读0次

原因分析:

Tomcat 7.0 以上版本为了安全,会对一些特殊字符进行编码,导致 400 错误。

解决方法:

  1. 找到 config/catalina.properties 最后一行,去掉注释 # 在最后加一个 {}
# tomcat.util.http.parser.HttpParser.requestTargetAllow=|

改为:

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
  1. 如果 json 字符串中还存在 [],则还需要在 config/server.xml 中的 Connector 中添加:relaxedQueryChars="[,]"
<Connector URIEncoding="UTF-8" 
           port="8080" 
           protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443"
           relaxedQueryChars="[,]" 
/>

如果还有其他特殊的字符串,可以直接添加到这个属性里,完美解决。

原文链接:https://blog.csdn.net/a116385895/article/details/105976626

相关文章

网友评论

      本文标题:Tomcat :URL 请求向后台传 json 字符串报 400

      本文链接:https://www.haomeiwen.com/subject/rccjhltx.html