每当我尝试在Mozilla Firefox浏览器中按如下所示在URL中添加特殊字符
时,或
Tomcat返回HTTP状态400 –错误的请求 和异常堆栈跟踪如下。
Type Exception Report
Message Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).
Exception
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:474)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)
Note The full stack trace of the root cause is available in the server logs.
令人惊讶的是,带有特殊字符的相同URL在Google Chrome浏览器中正常工作。
我有以下问题 1)我应该在tomcat配置文件中进行哪些更改,以使其不返回400状态代码和异常堆栈跟踪? 2)为什么Mozilla Firefox无法对URL进行编码?
注意:我已经在部署于tomcat 9的应用程序中为4XX类型的状态代码配置了一个公共页面,但问题是tomcat首先返回400错误的请求http状态代码作为响应。
答案 0 :(得分:0)
请从此处https://tomcat.apache.org/tomcat-8.5-doc/config/http.html中查看relaxedPathChars和relaxedQueryChars,您需要将它们设置为允许所有未转义的先前字符