个人问题接口是接口中包含 “^”特殊符号,tomcat 8.5.35报以下的错。html
Invalid character found in the request target. The valid characters are defined in RFC 3986
apache
从错误日志中看到Error parsing HTTP request header
tomcat
负责解析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="|{}[]^,"
完美解决问题!!!