zoukankan      html  css  js  c++  java
  • 已解决:Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986 问题

    请求:

    http://127.0.0.1:8080/driverApp/findLikeAddress?json={"shopname":"广东省","uid":1001}

    控制台报错:

    04-Aug-2020 12:03:09.642 信息 [http-nio-8080-exec-8] org.apache.coyote.http11.Http11Processor.service 解析 HTTP 请求 header 错误
     Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
        java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
            at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:483)
            at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:502)
            at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
            at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623)
            at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
            at java.lang.Thread.run(Thread.java:748)
     

    问题:Tomcat抛出异常,导致400 –错误请求。

    从7.0.88开始,大多数tomcat版本都会出现此问题。

    解决方案:(由Apache团队建议):

    Tomcat增强了其安全性,并且不再允许在查询字符串中使用原始方括号。在请求中,我们有{,} 或其他符号,因此服务器未处理该请求。

    在tomcat conf路径下的server.xml文件里面的 Connector 标签下添加属性 relaxedQueryChars:

    <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" 
                   maxHttpHeaderSize ="10240" 
                   relaxedQueryChars="{,}"/>

    如果应用程序需要默认情况下tomcat不支持的更多特殊字符,请在relaxedQueryChars上述属性中添加这些特殊字符,并以逗号分隔。

  • 相关阅读:
    开源项目中标准文件命名和实践
    linux远程拷贝命令-scp
    Linux访问Windows共享目录的方法——smbclient
    ADB Fix error : insufficient permissions for device
    APT典型应用示例
    我的参考书籍列表
    GCC Reference
    GNU make简介
    Windows下搭建Android NDK开发环境及命令行编译
    Git命令行基本操作
  • 原文地址:https://www.cnblogs.com/lyso/p/13433435.html
Copyright © 2011-2022 走看看