控制台报错信息:
org.apache.coyote.http11.AbstractHttp11Processor process 信息: 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.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:194) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1050) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:744)
解决方案及原因分析:
一、原因是Tomcat的header缓冲区大小不够,只需要在server.xml中增加maxHttpHeaderSize,设置如
<Connector connectionTimeout="20000" maxHttpHeaderSize="8999" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
二、使用了不安全字符,他们直接放在Url中的时候,可能会引起解析程序的歧义。如
{ } | \ ^ [ ] ` ~ % # 等
如果要在url里使用不安全字符,就需要使用转义。