其他分享
首页 > 其他分享> > The valid characters are defined in RFC 7230 and RFC 3986

The valid characters are defined in RFC 7230 and RFC 3986

作者:互联网

完整报错:

org.apache.coyote.http11.Http11Processor.service 解析 HTTP 请求 header 错误
 Note: further occurrences of HTTP request 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:483)
                at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:502)
                at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
                at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
                at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
                at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
                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)

错误原因:

  1. 请求内容中包含特殊字符
  2. 浏览器get请求传入参数长度过长
  3. tomcat版本过高

解决办法:

  1. 页面级解决办法:使用js自带的函数encodeURIComponent(inInfo)将包含特殊字符的字符串转义
  2. tomcat级解决办法:

        (1.) 修改tomcat/config下的catalina.properties文件:

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

                        或者

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

       (2.) 修改tomcat/config下的server.xml文件中

 <Connector port="9080" protocol="HTTP/1.1"
               connectionTimeout="20000"   URIEncoding="UTF-8" 
               maxHttpHeaderSize ="22240"
               relaxedPathChars="[]{}|^"
               relaxedQueryChars="{,}"
               redirectPort="8443" />

标签:util,java,tomcat,defined,RFC,characters,coyote,apache,org
来源: https://blog.csdn.net/mah666/article/details/119383637