Invalid character found in the request target
在高版本的Tomcat下,get传值不能有 [ {等等特殊字符
解决办法
如果是Spring-boot项目,可以添加一个TomcatConfig.java类
package com.roboterh.fastjsondemo.config;
import org.apache.catalina.connector.Connector;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class TomcatConfig {
@Bean
public TomcatServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers((Connector connector) -> {
connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
});
return factory;
}
}
在高版本的Tomcat中遇到Invalid character found in the request target的问题,主要是由于某些特殊字符如'[{等在GET请求中不被允许。针对此问题,可以通过在Spring-boot项目中创建一个TomcatConfig配置类,添加Bean来定制Tomcat连接器,设置relaxedPathChars和relaxedQueryChars属性,允许这些特殊字符。
5021

被折叠的 条评论
为什么被折叠?



