1. 程式人生 > >後臺報錯java.lang.IllegalArgumentException: Invalid character found in the request target.

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

報錯:

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=|{} ,成功解決問題。