本问题核心原因是http协议升级,因为网络安全问题日益严峻,RFC组织决定将RFC2616拆分并进行升级。
RFC2616拆分后:
- RFC7230 - HTTP/1.1: Message Syntax and Routing - low-level message parsing and connection management
- RFC7231 - HTTP/1.1: Semantics and Content - methods, status codes and headers
- RFC7232 - HTTP/1.1: Conditional Requests - e.g., If-Modified-Since
- RFC7233 - HTTP/1.1: Range Requests - getting partial content
- RFC7234 - HTTP/1.1: Caching - browser and intermediary caches
- RFC7235 - HTTP/1.1: Authentication - a framework for HTTP authentication
今天出现问题的主角也和上面有关,还涉及一个协议
RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax
因为防止sql注入,新RFC将|视为非法路径符号。
解决方法如下:
undertow RFC 7230 and RFC 3986 compatibility
代码
@Bean public ConfigurableServletWebServerFactory webServerFactory() { UndertowServletWebServerFactory factory =new UndertowServletWebServerFactory(); factory.addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ALLOW_UNESCAPED_CHARACTERS_IN_URL, Boolean.TRUE)); //url配置 factory.addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, Boolean.TRUE)); factory.addBuilderCustomizers(builder -> builder.setServerOption(UndertowOptions.ALLOW_ENCODED_SLASH,Boolean.TRUE)); return factory; }
参考资料:https://my.oschina.net/qinerg/blog/3122953
Tomcat解决办法:
@Bean public ConfigurableServletWebServerFactory webServerFactory() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override public void customize(Connector connector) { connector.setProperty("relaxedQueryChars", "|{}[]"); } }); return factory; }
参考:https://stackoverflow.com/questions/46251131/invalid-character-found-in-the-request-target-in-spring-boot
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。