後臺報錯java.lang.IllegalArgumentException: Invalid character found in the request target.

報錯:java

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……

 

錯誤緣由:apache

當在瀏覽器中訪問時 URL中帶有特殊字符,如花括號冒號時,就會出現這個錯誤。瀏覽器

例如:http://localhost:8080/index.do?{id:123}tomcat

解決方法:

一、去除URL中的特殊字符;服務器

三、使用 Post 方法提交數據spa

四、更換低版本的Tomcat來規避這種問題。code

五、在 conf/catalina.properties  添加或者修改: blog

  5.1  添加  tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} get

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)io

 

重啓服務器後,解決問題。

總結:

我的本地在conf/catalina.properties 中添加   tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} ,成功解決問題。

相關文章
相關標籤/搜索