当前位置:   article > 正文

Java.lang.IllegalArgumentException: Invalid character found in the request target.

java.lang.illegalargumentexception: invalid character found in the request t

如何解决 Java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

近期在做一个关于CMS建站平台的项目在后台上传图片的时候遇到了 java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986这个错误,翻了许多博客发现用的方法都不行(基本上都是在Tomcat根目录的config中修改server.xml文件)于是集思广益花了我一个星期的时间终于解决了。

首先在我们Tomcat的根目录中找到我们的catalina.properties文件(文件位置:Tomcat根目录\conf\catalina.properties)。找到注释掉的一行 #tomcat.util.http.parser.HttpParser.requestTargetAllow=| ,改成tomcat.util.http.parser.HttpParser.requestTargetAllow=|{},表示把{}放行。

# This system property is deprecated. Use the relaxedPathChars relaxedQueryChars
# attributes of the Connector instead. These attributes permit a wider range of
# characters to be configured as valid.
# Allow for changes to HTTP request validation
# WARNING: Using this option may expose the server to CVE-2016-6816
#tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

之后则是跟众多博主的方法一样修改server.xml文件(文件位置:Tomcat根目录\conf\server.xml),但是修改的内容跟众多博主的不一样。在service.xml中添加realxedQueryChars属性,属性的值为"[,],|,{,},^,\,`,",<,>"。

 <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="utf-8" relaxedQueryChars="[,],|,{,},^,&#x5c;,&#x60;,&quot;,&lt;,&gt;"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"/>
    -->
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

修改这两处之后重新启动Tomcat服务器再运行项目,图片就能够成功上传,不会再在控制台上遇到java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986错误的提示了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/282325
推荐阅读
相关标签
  

闽ICP备14008679号