当前位置:   article > 正文

java.lang.IllegalArgumentException: Invalid character found in the request target 异常

java.lang.illegalargumentexception: invalid character found in the request t

Note: further occurrences of HTTP request parsing errors will be
logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in the
request target. The valid characters are defined in RFC 7230 and RFC
3986

一、在发送请求头参数给后端的时候会出现上述异常,这是由于tomcat配置引起,在SpringBoot项目中添加如下配置类即可。

/**
 * @author 码不多
 * @version 1.0
 * @description: 解决java.lang.IllegalArgumentException:Invalid character found in the request 异常
 * @date 2022/1/9 20:54
 */
@Configuration
public class TomCatConfig {
    @Bean
    public TomcatServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers((Connector connector) -> {
            connector.setProperty("relaxedPathChars", "\"<>[\\]^`{|}");
            connector.setProperty("relaxedQueryChars", "\"<>[\\]^`{|}");
        });
        return factory;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

二、当请求头的参数过长时会出现 :

Note: further occurrences of HTTP request parsing errors will be
logged at DEBUG level.

java.lang.IllegalArgumentException: Request header is too larg

上述异常解决办法 : 修改application.properties或yaml配置文件添加 :

server.max-http-header-size=102400

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/282330
推荐阅读
相关标签
  

闽ICP备14008679号