解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

原因:这个问题是高版本tomcat中的新特性:就是严格按照 RFC 3986规范进行访问解析,而 RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。而我们的系统在通过地址传参时,在url中,传入的参数中有”[“不在RFC3986中的保留字段中,所以会报这个错。

简单的解决办法是在tomcat的配置文件server.xml中修改 connector的属性,添加relaxedQueryChars如下:

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" relaxedQueryChars="[]|{}^&#x5c;&#x60;&quot;&lt;&gt;"
redirectPort="8443" maxThreads="500" minSpareThreads="50" maxSpareThreads="100"
enableLookups="false" acceptCount="500" />

原文地址:https://www.cnblogs.com/gangzi4321/p/14857826.html