终极解决方案: Invalid character found in the request target.

终极解决方案:(导出可能出现)

我的tomcat版本是8.5.32,导出时遇到以下报错。

报错日志

Invalid character found in the request target. The valid characters are defined in RFC 3986

从错误日志中看到对请求URL中对字符做了限制。

解决方法

1.在tomcat安装路径中conf/catalina.properties中最后添加2行:

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

网上还有一些掩耳盗铃的做法,就是降低tomcat的版本。Tomcat在 8.5版本后,在http解析时做了严格限制。

requestTargetAllow 只能配置|、{、} 这三个字符,对于其他的(例如" < > [ \ ] ^ ` { | } .),依旧报错,如果使用了|{}之外的其他字符,那就还需要如下配置。

2.在conf/server.xml中的<Connector>节点中,添加2个属性(可以接收任意特殊字符的组合,自行配置):

relaxedPathChars="|{}[],\"
relaxedQueryChars="|{}[],\"
posted @ 2019-12-19 14:19  二次元的程序猿  阅读(13661)  评论(0编辑  收藏  举报