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

來源:互聯網
上載者:User

標籤:方法   轉換   code   AC   span   header   exce   evel   特殊   

報錯:

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

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.