tomcat异常解决(Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986)

2025-05-26 0 103

1.情景展示

  tomcat 日志时不时会报出如下异常信息,到底是怎么回事?

?

1

2

3

4

5

6

7

8

9

10
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.abstractnioinputbuffer.parserequestline(abstractnioinputbuffer.java:283)

at org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1017)

at org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:684)

at org.apache.tomcat.util.net.nioendpoint$socketprocessor.dorun(nioendpoint.java:1520)

at org.apache.tomcat.util.net.nioendpoint$socketprocessor.run(nioendpoint.java:1476)

at java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142)

at java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617)

at org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61)

at java.lang.thread.run(thread.java:745)

  页面无法打开

tomcat异常解决(Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986)

2.原因分析  

  意思是:请求头中包含了 rfc 7230 and rfc 3986规范中定义的非法字符,在这种情况下就会导致页面报400异常

  原因就是:tomcat的版本过高造成的,网上说,tomcat高于 7.0.73的版本,添加了对于http头(请求头)的验证。

  get请求,即问号传参,就是只有请求头,没有请求体

  rfc3986文档规定,url中只允许包含英文字母(a-za-z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符。

  rfc3986中指定了以下字符为保留字符:! * ' ( ) ; : @ & = + $ , / ? # [ ]

  同时rfc 3986规范在tomcat7.0.73版本中就已经提出了,rfc 7230也是对前者的一些补充或者说是完善,所以在tomcat7.0.73及以上版本都会有这种问题。

  说明:这种情况,只在ie浏览器下会出现,因为ie浏览器不会对中文参数进行编码,而其它类型的浏览器会默认自动对中文进行编码。

3.解决方案

  方法一:降低tomcat版本;

  经过测试发现,网上关于tomcat的最高版本要求描述有误,不是低于7.0.73就可以。

  我下载了一个tomcat7.0.70,运行项目后,还是会字符集的错误,导致网页无法打开。

  但是,我测了tomcat7.0.61,完美正常运行项目,控制台不再报错,网页可以正常打开了。

tomcat异常解决(Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986)

  64位下载地址:https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61-windows-x64.zip

  32位下载地址:https://archive.apache.org/dist/tomcat/tomcat-7/v7.0.61/bin/apache-tomcat-7.0.61-windows-x86.zip

  方法二:将get请求改为post请求;(推荐使用)

  方法三:get请求(问号传参)

  使用uriencoder()函数,将中文进行编码

以上就是tomcat异常解决(invalid character found in the request target. the valid characters are defined in rfc 7230 and rfc 3986)的详细内容,更多关于tomcat 异常解决的资料请关注快网idc其它相关文章!

原文链接:https://www.cnblogs.com/Marydon20170307/p/10343098.html

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 tomcat异常解决(Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986) https://www.kuaiidc.com/54362.html

相关文章

发表评论
暂无评论