摘要:文件下载时,出现如下异常信息:
2020-08-24 16:18:35:136 Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level. [org.apache.coyote.http11.Http11Processor:175]-[INFO]
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:488)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)
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)
2020-08-24 16:18:35:468 Weight adjusting job started [com.netflix.loadbalancer.WeightedResponseTimeRule:248]-[INFO]
问题分析
根据:https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html requestTargetAllow已弃用。 对我来说,这里介绍的其他解决方案也不起作用。 根据Tomcat文档,我找到了一种设置属性RelaxedQueryChars的方法:
解决办法
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setProperty("relaxedQueryChars", "|{}[]");
}
});
return factory;
}