解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF

Posted 魔流剑●风之痕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF相关的知识,希望对你有一定的参考价值。

通过这里的回答,我们可以知道:

Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证。

具体来说,就是添加了些规则去限制HTTP头的规范性

参考这里

具体来说:

org.apache.tomcat.util.http.parser.HttpParser#IS_NOT_REQUEST_TARGET[]中定义了一堆not request target

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看):

  • 键盘上那些控制键:(<32或者=127)
  • 非英文字符(>127)
  • 空格(32)
  • 双引号(34)
  • #(35)
  • <(60)
  • >(62)
  • 反斜杠(92)
  • ^(94)
  • TAB上面那个键,我也不晓得嫩个读(96)
  • {(123)
  • }(124)

   |(125)

  解决办法1:

  还是参考这里

  即:

  配置tomcat的catalina.properties

  添加或者修改:

  tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

   这种方法只适合对应的应为,如果为中文则就不行。如果有?和&这些符合那么

  tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}?&

  解决办法2:

  最轻便的方法,更换tomcat版本。此方法比较快

  解决办法3:

  对相应的参数进行编码,就是将所有的参数都进行编码

  解决方法4:

  选择另外的参数传递方法,比如post或者localStorage。

 

  本人采用的是直接更换tomcat版本,应为参数中包含中文,代码已经写好。不想修改,就直接还tomcat。当然,这种问题在Google浏览器中未发现,基本都是IE浏览器中出现。

  需要更换那些版本的tomcat,可以直接下载对应的版本的tomcat

  http://archive.apache.org/dist/tomcat/tomcat-6/

  http://archive.apache.org/dist/tomcat/tomcat-7/

  http://archive.apache.org/dist/tomcat/tomcat-8/

  http://archive.apache.org/dist/tomcat/tomcat-9/

以上是关于解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF的主要内容,如果未能解决你的问题,请参考以下文章

Invalid character found in method name. HTTP method names must be tokens 解决办法

解决:Invalid character found in method name. HTTP method names must be tokens

解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF

解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF

解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF

解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF