報錯:
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……
錯誤原因:
當在瀏覽器中訪問時 URL中帶有特殊字符,如花括號冒號時,就會出現這個錯誤。
例如:http://localhost:8080/index.do?{id:123}
解決方法:
1、去除URL中的特殊字符;
3、使用 Post 方法提交數據
4、更換低版本的Tomcat來規避這種問題。
5、在 conf/catalina.properties 添加或者修改:
5.1 添加 tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
5.2 修改tomcat/conf/catalina.properties的配置文件
Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了對於http頭的驗證。
具體來說,就是添加了些規則去限制HTTP頭的規范性
org.apache.tomcat.util.http.parser.HttpParser#IS_NOT_REQUEST_TARGET[]中定義了一堆not request target
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;
}
轉換過來就是以下字符(對應10進制ASCII看):
鍵盤上那些控制鍵:(<32或者=127)
非英文字符(>127)
空格(32)
雙引號(34)
#(35)
<(60)
>(62)
反斜杠(92)
^(94)
TAB上面那個鍵,我也不曉得嫩個讀(96)
{(123)
}(124)
|(125)
重啟服務器后,解決問題。
總結:
個人本地在conf/catalina.properties 中添加 tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} ,成功解決問題。