1
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.

asked May 26, 2024 at 2:01
5
  • It looks like the sender side has encoding issues when setting the name in the request. Do you know what the original name value was or which language/encoding was? I guess that if the sender sends garbage characters it is hard for you to do something. Commented May 26, 2024 at 7:47
  • (1) 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. Commented May 26, 2024 at 15:54
  • Encoding Issue "The valid characters are defined in RFC 7230 and RFC 3986" in Tomcat 9 (stackoverflow.com/questions/56794459/…) Commented May 26, 2024 at 15:55
  • If you insist on The sending side of the code can not be modified, this problem should not be solved. Commented May 26, 2024 at 16:00
  • There doesn't seem to be a good solution at the moment, with JSON data being pushed, so the URL query parameters are not used, and I use NGINX to eliminate the following illegal query parameters Commented May 27, 2024 at 5:54

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.