The valid characters are defined in RFC 7230 and RFC 3986

 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
    at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:189)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1000)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

最新的tomcat6,7,8增加了新特性,就是严格按照 RFC 3986规范进行访问解析,而 RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。传入的参数中有"{"不在RFC3986中的保留字段中,所以会报这个错。

或者更改tomcat版本,或者修改传递参数信息,或者上传之前进行url编码

修改tomcat的配置文件

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>

 

解决办法有很多方式,具体如下几种:

1. 遵循7230 and RFC 3986规范,对于非保留字字符做转义操作

2. 使用保留字字符

3. 降低tomcat版本

4. 将json数据进行urlencode编码

个人建议从目前的角度出发使用第三种方式降低tomcat版本就可以了,如果从长远出发的话,建议遵循RFC 7230 and RFC 3986规范,对于非保留字字符(json格式的请求参数)做转义操作

原文地址:https://www.cnblogs.com/dashuai01/p/6894972.html