Open Maple-mxf opened 4 years ago
java.lang.IllegalArgumentException: Invalid character found in the request target [/restdoc/document/80c09aafab9e3781bd05cb725a5eb84e/snippet/view?type=requestBody&field=data[]]. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:491)
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:1590)
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无法解析
解决方案1 1-0 修改Tomcat配置 1-1 修改springboot配置
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setProperty("relaxedQueryChars", "|{}[]");
}
});
return factory;
}
解决方案2 encode特殊字符
js encode
encodeURIComponent("string")
java decode
URLDecoder.decode(path, StandardCharsets.UTF_8.name())
http://localhost:8432/restdoc/document/80c09aafab9e3781bd05cb725a5eb84e/snippet/view?type=requestBody&field=data[0].componentName