背景

在将tomcat升级到7.0.81版后,发现系统的有些功能不能使用了,查询日志发现是有些地址直接被tomcat认为存在不合法字符,返回HTTP 400错误响应,错入信息如下:

原因分析

经了解,这个问题是高版本tomcat中的新特性:就是严格按照 RFC 3986规范进行访问解析,而 RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。而我们的系统在通过地址传参时,在url中传了一段json,传入的参数中有"{"不在RFC3986中的保留字段中,所以会报这个错。

根据(https://bz.apache.org/bugzilla/show_bug.cgi?id=60594) ,从以下版本开始,有配置项能够关闭/配置这个行为:
8.5.x系列的:8.5.12 onwards
8.0.x系列的:8.0.42 onwards
7.0.x系列的:7.0.76 onwards

处理方法

.../conf/catalina.properties中,找到最后注释掉的一行 #tomcat.util.http.parser.HttpParser.requestTargetAllow=|  ,改成tomcat.util.http.parser.HttpParser.requestTargetAllow=|{},表示把{}放行

------2018.01.30 新增--------
按照上面的方法处理好后,在非IE浏览器上访问,是没有问题了。但若是在IE浏览器上进行访问,这个错误还是会出现,在IE上访问出现这个错误的原因:因为url的参数json中有双引号,火狐和谷歌浏览器会自动对url进行转码,但IE不会

这种情况的处理方法:
给系统配置方向代理服务器,通过反向代理服务器进行urlrewrite,手动取出各个json的数据,手动将双引号进行转码为%22:

具体方式如下:
编辑 Apache安装目录/conf/httpd.conf, 在配置项目反向代理的前面添加如下信息:

RewriteCond %{QUERY_STRING} json
RewriteCond %{QUERY_STRING} !msKey
RewriteCond %{QUERY_STRING} msInfo
RewriteCond %{QUERY_STRING} player
RewriteCond %{QUERY_STRING} {[^a-zA-Z0-9]([a-zA-Z]+)[^a-zA-Z0-9]:[^a-zA-Z0-9]([a-zA-Z0-9*]+)[^a-zA-Z0-9],[^a-zA-Z0-9]([a-zA-Z]+)[^a-zA-Z0-9]:[^a-zA-Z0-9]([a-zA-Z0-9*]+)[^a-zA-Z0-9]}
RewriteRule ^(.*)? $1?method=sendJson&json={%22%1%22:%22%2%22,%22%3%22:%22%4%22} [R,L,NE]

参考

https://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html(官网各配置项说明)

解决:Invalid character found in the request target.The valid characters are defined in RFC 7230 and RFC3986的更多相关文章

  1. 解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 问题

    通过这里的回答,我们可以知道: Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证. 具体来说,就是添加了些规则去限制HTTP头的规范性 参考这里 具体来说 ...

  2. 解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF

    通过这里的回答,我们可以知道: Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证. 具体来说,就是添加了些规则去限制HTTP头的规范性 参考这里 具体来说 ...

  3. Invalid character found in the request target.The valid characters are defined in RFC 7230 and RFC3986

    Tomcat在 7.0.73, 8.0.39, 8.5.7 版本后,添加了对于http头的验证. 具体来说,就是添加了些规则去限制HTTP头的规范性 参考这里 具体来说: org.apache.tom ...

  4. 关于toncat的Invalid character found in the request target.The valid characters are defined in RFC 7230 and RFC3986

    首先这个错误通常的产生原因, 是tomcat的确收到了格式不正确的请求参数,根据tomcat的版本支持的解析,tomcat抛出这个错误. 但是还有一种就是前台发送的请求方式由 get发送导致本应pos ...

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

    解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF ...

  6. 解决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请求 ...

  7. 已解决: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":"广东省"," ...

  8. 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 ...

  9. Tomcat报错Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986

    问题描述:后台报错 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.java ...

随机推荐

  1. HBase操作一

    package Hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.a ...

  2. 05ICMP协议与ARP协议(IP协议中重要协议)

    ICMP协议在网络层,应用:ping命令,tracert命令:追踪命令,用于静态路由. ICMP重定向 redirect

  3. pyhton习题20190201

    #20190131'''检查ipV4的有效性,有效则返回True,否则返回False,(提示使用split函数进行分割)'''import osdef print_ping_ip(ip): s = o ...

  4. 几个并发的术语解释——QPS,TPS,PV

    从英文全称翻译出字面意思就OK啦!  PV=page view TPS=transactions per second QPS=queries per second RPS=requests per ...

  5. (The application/json Media Type for JavaScript Object Notation (JSON))RFC4627-JSON格式定义

    原文  http://laichendong.com/rfc4627-zh_cn/ 摘要 JavaScript Object Notation (JSON)是一个轻量级的,基于文本的,跨语言的数据交换 ...

  6. 使用Java Api 对HBase进行简单操作

    /** * 功能:测试Hbase基本的增删改查操作 * Created by liuhuichao on 2016/12/5. */ public class HbaseCRUDTest { publ ...

  7. 【LG3321】[SDOI2015]序列统计

    [LG3321][SDOI2015]序列统计 题面 洛谷 题解 前置芝士:原根 我们先看一下对于一个数\(p\),它的原根\(g\)有什么性质(好像就是定义): \(g^0\%p,g^1\%p,g^2 ...

  8. Android:制作聊天气泡点9图

    步骤一:选择res下的一张图片,右击选择“Create 9-Patch File” 步骤二:确定点9图的名字,只能修改.9.png之前的信息 步骤三:在同目录下会生成刚才创建的点9图,双击打开进行编辑 ...

  9. selenium webdriver API详解(三)

    本系列主要讲解webdriver常用的API使用方法(注意:使用前请确认环境是否安装成功,浏览器驱动是否与谷歌浏览器版本对应) 一:获取页面元素的文本内容:text 例:获取我的博客名字文本内容 代码 ...

  10. selenium自动化之元素定位方法

    在使用selenium webdriver进行元素定位时,有8种基本元素定位方法(注意:并非只有8种,总共来说,有16种). 分别介绍如下: 1.name定位 (注意:必须确保name属性值在当前ht ...