最近部署項目的時候,由於MIS配置的是Tomcat 8.5的服務端,導致Web應用不正常,報HTTP 400錯誤(Chrome無異常、IE報錯)。問題原因初步判斷爲8.5版本的服務端接收請求不會對符號進行轉義,Chrome不異常的原因或許是瀏覽器自身轉義了。具體錯誤信息如下:
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
查閱了大量資料後,有兩種解決方案:
Plan 1:
更換低版本的Tomcat來規避這種問題。
Plan 2:
在conf/catalina.properties中最後添加一行:
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
重啓服務器後,解決問題。
官方指南地址:http://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html
官方說明:
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH
If this is true ‘%2F’ and ‘%5C’ will be permitted as path.delimiters.If not specified, the default value of false will be used.