java.lang.IllegalArgumentException: Invalid character found in the request target [/t?personId=1308338881684471809&name=0xe40xbd0x950xe50xa40xa70xe70x840xb1&type=face_0&time=1716555197143]. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:486) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:261) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.38.jar:9.0.38]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_251]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_251]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.38.jar:9.0.38]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_251]
Invalid character found in the request target I think it's possible that the requested URL contains special characters Code has been added to the startup class
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
fa.addConnectorCustomizers(connector -> {
// connector.setProperty("relaxedQueryChars", "[]{}");
connector.setProperty("relaxedPathChars", "\"#<>[\\]^`{|}%,");
connector.setProperty("relaxedQueryChars", "\"#<>[\\]^`{|}%,");
});
return fa;
}
But the error remains Discover the existence of special characters by grabbing the bag enter image description here The sending side of the code can not be modified, can only modify the receiving side of the code, now need how to solve
After testing, I found that the encoding sent was UTF-8,My server version is Tomcat9.0.38.At the moment I am dealing with special symbols, but the results do not seem to solve the problems encountered,I've also configured ‘spring.http.encoding.charset’ and ‘server.tomcat.url-encoding.charset’ Encoding. Charset I think it might be a good idea to allow all of Utf-8's encoding, and I'm currently trying to figure out how to do that.
curl -X POST "http://localhost:8080/t?personId=1308338881684471809&name=何大焱&type=face_0&time=1716555197143"will get same error (2) encode "何大焱" to "%E4%BD%95%E5%A4%A7%E7%84%B1" ,curl -X POST "http://localhost:8080/t?personId=1308338881684471809&name=%E4%BD%95%E5%A4%A7%E7%84%B1&type=face_0&time=1716555197143", you can pass. (3) This is Tomcat 8.5+ Apply HTTP RFC 7230 and RFC 3986 , you can add some extra chars in relaxedPathChars & relaxedQueryChars , but out of these extra chars, is still failed.Encoding Issue "The valid characters are defined in RFC 7230 and RFC 3986" in Tomcat 9(stackoverflow.com/questions/56794459/…)The sending side of the code can not be modified, this problem should not be solved.