問題出現:
tomcat由7.0.65升級到7.0.104后出現該問題
java.lang.IllegalArgumentException:在請求目標中找到無效字符。有效字符在RFC 7230和RFC 3986中定義
原因分析:
日志顯示請求地址中包含不合法字符,出現400錯誤
tomcat高版本嚴格按照RFC 3986規范解析地址。該規范只允許包含 a-zA-Z 0-9 - _ . ~ 以及所有保留字符 ! * ’ ( ) ; : @ & = + $ , / ? # [ ]
7.0.65時地址中包含{},所以該地址在tomcat升級后出問題
解決辦法:
一、在tomcat安裝路徑\conf\catalina.properties中,找到注釋掉的一行 #tomcat.util.http.parser.HttpParser.requestTargetAllow=| ,改成tomcat.util.http.parser.HttpParser.requestTargetAllow=|{},表示把{}放行
二、 在./conf/service.xml中添加realxedQueryChars屬性
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="30000" maxThreads="800" minSpareThreads="50" redirectPort="8443" URIEncoding="ISO-8859-1" relaxedQueryChars="[,],|,{,},^,\,`,",<,>"/>