背景
在使用Tomcat8部署项目做测试的时候,发现有的接口会报错400,后端提示在请求目标中找到无效字符。有效字符在RFC 7230和RFC 3986中定义的错误
原因
因为日志显示请求地址中包含不合法字符,出现400错误,
tomcat高版本严格按照RFC 3986规范解析地址。该规范只允许包含 a-zA-Z 0-9 - _ . ~ 以及所有保留字符 ! * ’ ( ) ; : @ & = + $ , / ? # [ ] 符号 。
但是项目在发起请求的参数中出现{}符号。
解决方法
在tomcat配置文件中做出以下配置,找到tomcat配置中的server.xml文件。
解决方案:找到apache-tomcat-7.0.105\conf\server.xml:
<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
修改为:<Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8" relaxedPathChars="|{}[],%" relaxedQueryChars="|{}[],%" />
relaxedPathChars=“|{}[],%” relaxedQueryChars=“|{}[],%”
加上红色框中的代码 问题解决。
尤其是原IE浏览器出现该问题,当前火狐、google、edge需要校验。
评论 (0)