GET请求添加了JSON参数值出现该异常
java.lang.IllegalArgumentException: Invalid character found in the request target
The valid characters are defined in RFC 7230 and RFC 3986
原因:
tomcat8不允许URL中出现"[]"字符
解决方案:
方案1:对参数进行UrlEncode
方案2:改为post请求
方案3:tomcat降级(没试,不推荐)
方案4:修改tomcat配置,忽略特殊字符(没试)
方案5:springboot,jar包部署,启动类添加如下代码,tomcat忽略特殊字符
@Beanpublic ConfigurableServletWebServerFactory webServerFactory() {TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();factory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> connector.setProperty("relaxedQueryChars", "|{}[]\\"));return factory;}