我的应用程序是使用java -jar以及1.5.6.RELEASE版本的spring boot启动的。 我的请求之一的内容为字符“ {”。将其发送到服务器时,会引发以下异常:
java.lang.IllegalArgumentException:在请求目标中找到无效字符。有效字符在org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:472)和org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:683)的RFC 7230和RFC 3986中定义org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor上的org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:868)在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)处的doRun(NioEndpoint.java:1455)在java.util处的java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)处的doRun(NioEndpoint.java:1455) .concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor。
哪里错了?我如何解决它?
EDIT1: 我的休息是这样的:
var jsonData = { id: $("#hiddenId").val(), permitNumber: $("#txtPermitNumber").val(), permitToDate: $("#txtPermitToDate").val() } document.location = restUrl + "/print?reportParams= " + JSON.stringify(jsonData);
据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; }