Tomcat報錯解決 --- The valid characters are defined in RFC 7230 and RFC 3986

個人問題接口是接口中包含 「^」特殊符號,tomcat 8.5.35報以下的錯。html

Invalid character found in the request target. The valid characters are defined in RFC 3986apache

從錯誤日誌中看到Error parsing HTTP request headertomcat

負責解析http請求的是org.apache.tomcat.util.http.parser.HttpParser,它對請求對URL中對字符作了限制,具體代碼以下:
IS_NOT_REQUEST_TARGET[]中定義了一堆not request targeturl

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),也就是URL中不能包含的特殊字符:spa

  • 鍵盤上那些控制鍵:(<32或者=127)
  • 非英文字符(>127)
  • 空格(32)
  • 雙引號(34)
  • #(35)
  • <(60)
  • >(62)
  • 反斜槓(92)
  • ^(94)
  • TAB上面那個鍵,~(96)
  • {(123)
  • }(124)
  • |(125)

本身整了很久,baidu到的全都是這樣的:

在conf/catalina.properties中最後添加2行:日誌

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

我是這麼加的。code

tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}^
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

可是個人問題仍是沒有解決 ,經過查看文檔發現了這些個東西:server

就是說這個配置只能處理接受的字符爲 { } |  ,哭了......xml

文檔地址:https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html
 在猶豫是否是要下降版本屈服的時候在文檔中搜索了 「^」符號發現了這個。。。因而乎htm

文檔地址:https://tomcat.apache.org/tomcat-8.5-doc/config/http.html

在conf/server.xml中的<Connector port="8080">節點中,添加2個屬性:

relaxedPathChars="|{}[]^,"
relaxedQueryChars="|{}[]^,"

完美解決問題!!! 

相關文章
相關標籤/搜索