The valid characters are defined in RFC 7230 and RFC 3986

针对Tomcat Server报错: “The valid characters are defined in RFC 7230 and RFC 3986”


解决方案大全:

1、针对于SpringBoot jar启动的项目:

直接在yml中配置:

server.tomcat.relaxedQueryChars=<,>, [,\,],^,`,{,|,}


2、针对tomcat war包部署的任何项目:

修改server.xml文件,如下:

<Connector port="8084" protocol="HTTP/1.1" 
    relaxedPathChars="[]|" relaxedQueryChars="[]|{}^&#x5c;&#x60;&quot;&lt;&gt;" 
    useBodyEncodingForURI="true" connectionTimeout="20000" redirectPort="8443" 
    URIEncoding="UTF-8"/>


3、重载spring boot autoconfigure(非常不建议这么做

@Bean
@ConditionalOnClass(name = "org.apache.catalina.startup.Tomcat")
public ConfigurableServletWebServerFactory webServerFactory() {
    // 可选字符:< > [ \ ] ^ ` { | }
    // 等价于yml配置:server.tomcat.relaxedQueryChars=<,>, [,\,],^,`,{,|,}
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> 
            connector.setProperty("relaxedQueryChars", "|{}[]\\"));
    return factory;
}


© 2009-2020 Zollty.com 版权所有。渝ICP备20008982号