后台报错java.lang.IllegalArgumentException: Invalid character found in the request target.

报错:java

Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level. java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986……

 

错误缘由:apache

当在浏览器中访问时 URL中带有特殊字符,如花括号冒号时,就会出现这个错误。浏览器

例如:http://localhost:8080/index.do?{id:123}tomcat

解决方法:

一、去除URL中的特殊字符;服务器

三、使用 Post 方法提交数据spa

四、更换低版本的Tomcat来规避这种问题。code

五、在 conf/catalina.properties  添加或者修改: blog

  5.1  添加  tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} get

5.2  修改tomcat/conf/catalina.properties的配置文件
Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证。
具体来讲,就是添加了些规则去限制HTTP头的规范性
org.apache.tomcat.util.http.parser.HttpParser#IS_NOT_REQUEST_TARGET[]中定义了一堆not request target
if(IS_CONTROL[i] || i > 127 || i == 32 || i == 34 || i == 35 || i == 60 || i == 62 || i == 92 || i == 94 || i == 96 || i == 123 || i == 124 || i == 125) {
IS_NOT_REQUEST_TARGET[i] = true;
}
转换过来就是如下字符(对应10进制ASCII看):
键盘上那些控制键:(<32或者=127)
非英文字符(>127)
空格(32)
双引号(34)
#(35)
<(60)
>(62)
反斜杠(92)
^(94)
TAB上面那个键,我也不晓得嫩个读(96)
{(123)
}(124)
|(125)io

 

重启服务器后,解决问题。

总结:

我的本地在conf/catalina.properties 中添加   tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} ,成功解决问题。

相关文章
相关标签/搜索