• 已解决: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上述属性中添加这些特殊字符,并以逗号分隔。

  • 相关阅读:
    修改ubuntu DNS的步骤/wget url报错: unable to resolve host address的解决方法
    MySQL5.7 Replication主从复制配置教程
    总结一下安装linux系统经验-版本选择-安装ubuntu
    分布式与集群的联系与区别
    spring 后置处理器BeanFactoryPostProcessor和BeanPostProcessor的用法和区别
    mysql几种性能测试的工具使用
    mysql max_allowed_packet查询和修改
    mysql主从复制(超简单)
    10 个免费的网络监控工具(转)
    DOS批处理中%cd%和%~dp0的区别
  • 原文地址:https://www.cnblogs.com/lyso/p/13433435.html
Copyright © 2020-2023  润新知