欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

tomcat7.088报错Error parsing HTTP request header

程序员文章站 2024-02-28 19:55:46
...
八月 19, 2019 10:23:57 上午 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:1052)
	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:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

报错:The valid characters are defined in RFC 7230 and RFC 3986

项目环境使用的tomcat7.0.88

通过网上查找之前遇到此问题人的解决办法,发现Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,在http解析时做了严格限制,其根据RFC3986文档规定,请求的Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符。用浏览器地址输入的URL死活不能包含有任何特殊字符。否则会返回400 状态码。

若请求中包含| {  } 三个特殊字符,则使用如下配置即可解决(conf/catalina.properties):

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

若请求中包含除以上三个特殊字符以外的特殊字符,则需要(conf/server.xml的connector节点中增加如下配置(我项目上未用到此种方式,参考别人的):

relaxedPathChars="|{}[],"
relaxedQueryChars="|{}[],"

参考链接:https://yq.aliyun.com/articles/641394