background:
One problem appears on the Today program, it is in front of the GET request url with the path argument, which has / special character, the postman has shifted in the url become% 2F, the back-end using a springboot, and have not received this request, direct return 400 error
the reason:
Tomcat is said to be the default does not support the escape, it is necessary to manually set about transforming this search tomcat settings can be found, but this is springboot, there is a built-in tomcat, but could not find the relevant configuration in yml in.
Solution:
Modify the startup class, plus a system parameter, rewrite configurePathMatch method of WebMvcConfigurerAdapter.
@SpringBootApplication public class Application extends WebMvcConfigurerAdapter { public static void main(String[] args) throws Exception {
// step2: System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); SpringApplication.run(Application.class, args); }
// step1: @Override public void configurePathMatch(PathMatchConfigurer configurer) { UrlPathHelper urlPathHelper = new UrlPathHelper(); urlPathHelper.setUrlDecode ( false ); configurer.setUrlPathHelper (urlPathHelper); } }
4. How do local tomcat in this setting? (This example is a modification SpringBoot embedded tomcat configuration)
In tomcat directory /conf/catalina.properties add the following at the end of the file
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
Tomcat restart successfully solve the problem
url Transferred 5. Other common special characters as follows:
symbol | URL escaping results | Escape codes |
+ | + Sign indicates a space in the URL | % 2B |
Blank | URL spaces number or may be encoded + | %20 |
/ | Separate directories and subdirectories | % 2F |
? | And separating the actual URL parameters | % 3F |
% | Designated special characters | %25 |
# | Expressed bookmark | %23 |
& | Between specified in the URL parameter separator | %26 |
= | The value of the specified parameter in the URL | % 3D |