已解决:Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 问题

分类实验室日期2020-12-04 19:29:55访问230评论0

控制台报错

04-Aug-2020 12:03:09.642 信息 [http-nio-8080-exec-8] 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)

问题:Tomcat抛出异常,导致400 –错误请求!

从7.0.88开始,大多数tomcat版本都会出现此问题!

解决方案:(由Apache团队建议)

Tomcat增强了其安全性,并且不再允许在查询字符串中使用原始方括号.在请求中,我们有{,} 或其他符号,因此服务器未处理该请求!

在tomcat conf路径下的server.xml文件里面的 Connector 标签下添加属性 relaxedQueryChars:

<Connector port="8282" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxHttpHeaderSize ="10240"
relaxedPathChars="[]{}|\^" relaxedQueryChars="[]{}|\^" />/>

如果应用程序需要默认情况下tomcat不支持的更多特殊字符,请在relaxedQueryChars上述属性中添加这些特殊字符,并以逗号分隔!

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid charact

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

解决方法:

在Tomcat conf/catalina.properties 中最后添加一行:

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

tomcat.util.http.parser.HttpParser.requestTargetAllow=[]{}|\^

重启服务器后,解决问题!

扫描加入网页设计QQ群、建站如此简单

本文地址: https://www.usuuu.com/article/CuK5jES4

  • 暂无评论