The valid characters are defined in RFC 7230 and RFC 3986

报错信息

09-Apr-2019 14:55:11.427 信息 [http-nio-8089-exec-8] 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:748)

解决方法

1,在tomcat/conf/catalina.properties中添加下面这句话

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

2,在tomcat/conf/service.xml中在Connector标签中添加下面三个属性

URIEncoding="UTF-8"、relaxedPathChars="|{}[],"、relaxedQueryChars="[]|{}^\`"<>"

*这个是由于提交数据有特殊字符的原因,如果还有其他字符还可以往relaxedQueryChars中加。其他解决办法就是降低Tomcat8以下,和将提交的数据转码。

*以上修改只适合以下Tomcat版本 8.5.x~8.5.12 之间; 8.0.x~8.0.42 之间; 7.0.x~7.0.76 之间;

正在加载评论...