Spring Boot 04 -- 特殊字符传参报错

一、说明

springboot Invalid character found in the request target
正常的参数,在后台都是可以接收的,但是有时候会遇到一些比较奇怪的参数,带有特殊的字符例如



还有的参数里面会有大括号之类的
{}[]类似于这样的参数,后台不处理一般是接收不到的

二、解决方案

@SpringBootApplication
@EnableScheduling
@EnableFeignClients
public class ZhAlarmApplication {
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(ZhAlarmApplication.class, args);
        SpringContextUtil.setApplicationContext(context);
    }

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

如图在启动类中加入下面:

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

你可能感兴趣的:(Spring Boot 04 -- 特殊字符传参报错)