將皕杰報(bào)表demoserver中的演示項(xiàng)目report部署到Tomcat8最新版本后,當(dāng)訪問報(bào)表的URL中含有中文時(shí),訪問報(bào)表報(bào)錯(cuò)如下:
十一月 11, 2019 2:38:58 下午 org.Apache.coyote.http11.Http11Processor service
信息: Error parsing HTTP request header
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.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:479)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:684)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
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)
老版本Tomcat給版本不會(huì)出現(xiàn)這問題,經(jīng)排查發(fā)現(xiàn),原來最新的tomcat從7.0.73、8.0.39、8.5.7后增加了一個(gè)新特性,就是嚴(yán)格按照 RFC7230和RFC 3986規(guī)范進(jìn)行訪問解析,而 新規(guī)范定義了Url中只允許包含英文字母(a-zA-Z)、數(shù)字(0-9)、-_.~4個(gè)特殊字符以及所有保留字符(RFC3986中指定了以下字符為保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。
由于請(qǐng)求中包含了中文字符,所以tomcat無法正確解析請(qǐng)求參數(shù),導(dǎo)致出錯(cuò)。
解決方案:
1.降低tomcat的版本。
2.采用最新tomcat版本。對(duì)請(qǐng)求鏈接進(jìn)行編碼,report項(xiàng)目中所有編碼格式都改成utf-8;對(duì)訪問皕杰報(bào)表的鏈接進(jìn)行轉(zhuǎn)碼處理。