The valid characters are defined in RFC 7230 and RFC 3986

267 阅读1分钟

错误描述:

tomcat8 请求地址中包含 [],会出现 Invalid character found in the request target .The valid characters are defined in RFC 7230 and RFC 3986

 java.lang.IllegalArgumentException: Invalid character found in the request target [/lw-ueditor-backend-server/ueditor/oss/upload?source[]=http%3A%2F%2Flw-oss-develop.oss-cn-beijing.aliyuncs.com%2Ftemp%2F2021%E5%B9%B4%2Fimages%2F1622613924735.jpeg&action=catchimage&callback=bd__editor__1or35a ]. The valid characters are defined in RFC 7230 and RFC 3986
http://localhost:9000/lw-ueditor-backend-server/ueditor/oss/upload?source[]=http%3A%2F%2Flw-oss-develop.oss-cn-beijing.aliyuncs.com%2Ftemp%2F2021%E5%B9%B4%2Fimages%2F1622613924735.jpeg&action=catchimage&callback=bd__editor__1or35a

解决方法:

SpringbootApplication

image.png

  @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\"));
        return factory;
    }