在Spring Boot的请求目标中发现无效字符 [英] Invalid character found in the request target in spring boot
问题描述
我的应用程序以1.5.6版的java -jar启动.spring boot的发布.
我的请求之一的内容为字符"{".将其发送到服务器时,会引发以下异常:
My application is started with java -jar with version 1.5.6.RELEASE of spring boot.
The content of one of my request has the character "{".When it is sended to server the following exception is raised:
java.lang.IllegalArgumentException:在 请求目标.有效字符在RFC 7230和RFC中定义 3986年 org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:472) 在 org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683) 在 org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 在 org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:868) 在 org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1455) 在 org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在 org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
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:472) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) 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:745)
哪里出问题了? 我该如何解决?
Where is wrong? How do I fix it?
我的休息是这样的:
My rest is like this:
var jsonData = {
id: $("#hiddenId").val(),
permitNumber: $("#txtPermitNumber").val(),
permitToDate: $("#txtPermitToDate").val()
}
document.location = restUrl + "/print?reportParams= " + JSON.stringify(jsonData);
推荐答案
According to https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html, requestTargetAllow is deprecated. For me, the other solutions presented here did not work either. According to the Tomcat documentation I found a way to set the property relaxedQueryChars instead:
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setProperty("relaxedQueryChars", "|{}[]");
}
});
return factory;
}
这篇关于在Spring Boot的请求目标中发现无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!