請求參數含有特殊字符時後臺報這個錯誤:java
信息: Error parsing HTTP request header Note: further occurrences of HTTP header 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 at org.apache.coyote.http11.InternalAprInputBuffer.parseRequestLine(InternalAprInputBuffer.java:235) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1000) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)
查了資料緣由是 Tomcat在 7.0.73, 8.0.39, 8.5.7 版本後,添加了對於http頭的驗證。apache
安全字符tomcat
不安全字符安全
org.apache.tomcat.util.http.parser.HttpParser#IS_NOT_REQUEST_TARGET[]
中定義了一堆not request targetapp
if(IS_CONTROL[i] || i > 127 || i == 32 || i == 34 || i == 35 || i == 60 || i == 62 || i == 92 || i == 94 || i == 96 || i == 123 || i == 124 || i == 125) { IS_NOT_REQUEST_TARGET[i] = true; }
方案一:post
更換低版本的Tomcat來規避這種問題。編碼
使用 7.0.73 以前的版本url
方案二:.net
在conf/catalina.properties中最後添加一行:代理
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
或者,把要安全使用的放到配置後面
tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
方案三:
參數轉碼
encodeURI("http://localhost:8080/app/handleResponse?msg=name|id|") > http://localhost:8080/app/handleResponse?msg=name%7Cid%7C
升級Tomcat到8.5 後 , 出現這個問題. 經查證, 是Request url 中 , 出現了中文.
將參數encode後,問題解決!
[異常:Invalid character found in the request target. The valid characters are defined in RFC 3986 : 做者:碼上筆記]https://blog.csdn.net/ak57193856/article/details/77892749