线上环境中部署的 Tomcat 项目,出现部分页面无法打开的情况,但本地环境是好的。经过排查发现,本地 Tomcat版本为 7.0.77,而线上版本为 7.0.88。报错的具体描述为java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

描述

Tomcat 的日志如下:

INFO: Error parsing HTTP request header
Note: further occurrences of HTTP header 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

具体原因是,从 7.0.88 开始,Tomcat为了安全考虑,不在支持[,]这种参数传递方式了。解决办法如下,修改 $TOMCAT_HOME/conf/server.xml,新增 relaxedQueryChars="[,]"选项。

  1. 1
  2. 2
  3. 3
  1. <Connector port="8080" protocol="HTTP/1.1"
  2. connectionTimeout="20000"
  3. redirectPort="8444" relaxedQueryChars="[,]"/>
     

报错:

Note: further occurrences of HTTP header 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……

错误原因:

当在浏览器中访问时 URL中带有特殊字符,如花括号冒号时,就会出现这个错误。

例如:http://localhost:8080/index.do?{id:123}

解决方法:

1、去除URL中的特殊字符;

3、使用 Post 方法提交数据

4、更换低版本的Tomcat来规避这种问题。

5、在 conf/catalina.properties  添加或者修改:

  5.1  添加  tomcat.util.http.parser.HttpParser.requestTargetAllow=|{}

5.2  修改tomcat/conf/catalina.properties的配置文件
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)

重启服务器后,解决问题。

   

java.lang.IllegalArgumentException: Invalid character found in the request target. The valid charact的更多相关文章

  1. Tomcat v7.0 java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    十二月 , :: 下午 org.apache.coyote.http11.AbstractHttp11Processor process 信息: Error parsing HTTP request ...

  2. 解决springboot项目请求出现非法字符问题 java.lang.IllegalArgumentException:Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    springboot版本: 2.1.5 最近使用springboot搭建了一个App后台服务的项目,开发接口的时候在本机使用postman工具做请求测试,请求返回一直很正常,但是在前端开发使用h5请求 ...

  3. IE浏览器连接WebSocket报错:java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    在项目开发中整合了WebSocket,本来没什么问题了,但是偶尔发现用IE浏览器打开web端不能推送消息,因为PC端与服务器建立连接失败了.网上查了很多资料, 又看了看源码,都不对症:又怀疑是Spri ...

  4. Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors...java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are

    先将异常信息贴出: 该问题是tomcat进行http request解析的时候报的错,网上的解决办法主要是修改Tomcat的server.xml,在<Connector port="8 ...

  5. java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    微信小程序前后台使用get方式传参时报错如图.但在微信开发平台和苹果测试都没事,在安卓手机上就报这个错,猜想原因是get传递了汉字的原因. 尝试了下在后台输出从前台获取的参数,但是后台什么也没有获取到 ...

  6. 后台报错java.lang.IllegalArgumentException: Invalid character found in the request target.

    报错: Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level. java.lang ...

  7. java.lang.IllegalArgumentException: Invalid character found in the request target.

    java.lang.IllegalArgumentException: Invalid character found in the request target. http参数存在特殊字符: 特殊字 ...

  8. tomcat Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

      1.情景展示 tomcat 日志时不时会报出如下异常信息,到底是怎么回事? java.lang.IllegalArgumentException: Invalid character found ...

  9. 异常:Invalid character found in the request target. The valid characters are defined in RFC 3986

    一.背景 事情是这样的,前几天做一个基本的数据库“增删改查”的需求,前端传参的方式是“JSON字符串”,后端接收到此参数后,使用阿里巴巴fastjson进行解析,然后入库.需求很简单吧,但是偏偏遇到问 ...

随机推荐

  1. oracle--oracle18C DG搭建(二)

    配置清单 任务 数据库 创建主数据库数据文件的备份副本 主 为备用数据库创建控制文件 主 为备用数据库创建参数文件 主 将文件从主系统复制到备用系统 主 设置环境以支持备用数据库 备库 启动物理备用数 ...

  2. js原型和原型链,以及__proto__、prototype属性

    __proto__和prototype属性: 1.__proto__属性: 在JS里,万物皆对象(函数是对象.原型也是对象...).对象都具有属性__proto__,这个属性会指向该对象的原型. 2. ...

  3. google 镜像

    google 镜像 http://scholar.hedasudi.com/ http://ac.scmor.com/

  4. 如何在 VS2015 上开发 Qt 程序

    所有Qt版本下载地址: http://download.qt.io/archive/qt/ 所有Qt Creator下载地址: http://download.qt.io/archive/qtcrea ...

  5. Redis(九)高可用专栏之《简介篇》

    在互联网的大趋势下,用户体验.服务的可用性日趋重要.任何一个服务的不可用,都可能导致连锁式功能故障. 前言 高可用模型的已经逐渐形成一种套路: 主备/主从模式 集群模式 主备/主从模式 至少有两台服务 ...

  6. vue要求更新3.0-》使用axios的时候出现错误

    要求更新 使用axios报错 - Running completion hooks...error: 'options' is defined but never used (no-unused-va ...

  7. css层叠规则(层叠样式表)

    CSS层叠规则: 1.找出所有相关的规则,这些规则都包含与一个给定元素匹配的选择器. 2.按权重(!important)和来源对应用到给定元素的所有声明进行排序. 3.按特殊性对应用到给定元素的所有声 ...

  8. WampServer出现You don’t have permission to access/on this server提示

    WampServer出现You don’t have permission to access/on this server提示 本地搭建WampServer,输入http://127.0.0.1访问 ...

  9. android studio学习---怎么创建一个新的module并且再次运行起来(在当前的project里面)

    选择File->new module出现的界面,选择android application选择下一步,就出现了和刚刚一样的流程了,一步步创建完成即可. 我们看到多了个secondAndroid的 ...

  10. Android 培训准备资料之project与module的区别(1)

    project和module的区别? 现在我们来看看在Android studio中怎样新建一个project (1)file->new->new project. Application ...