最近遇到一个问题,比如GET请求中,key,value中带有特殊符号,请求会报错,见如下URL:
http://xxx.xxx.xxx:8081/aaa?key1=val1&a.\[\].id=123&b=a\[1\]
现在,我们进入boot启动类,添加如下代码即可:
public class DemoApp {
public static void main(String[] args) {
SpringApplication.run(DemoApp.class, args);
}
@Bean
public TomcatServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
}
});
return factory;
}
}