Open-source-sharing / REST-doc

RESTdoc Project is a document software that improves research and development efficiency. It integrates testing and document generation. It can quickly import the application's Http API or RPC API to quickly generate documents.
Apache License 2.0
1 stars 2 forks source link

字段备注编辑400错误 #23

Open Maple-mxf opened 4 years ago

Maple-mxf commented 4 years ago

http://localhost:8432/restdoc/document/80c09aafab9e3781bd05cb725a5eb84e/snippet/view?type=requestBody&field=data[0].componentName

Maple-mxf commented 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)
Maple-mxf commented 4 years ago

"[]"属于特殊字符,Tomcat无法解析

Maple-mxf commented 4 years ago

解决方案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())