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格式的請求參數)做轉義操作