tomcat请求参数问题解决: Invalid character found in the request target. The valid characters are defined in

错误还原:

今天升级tomcat7.0.84遇到一个问题:url请求中包含{}的都报错:

二月 06, 2018 5:25:39 下午 org.apache.coyote.http11.AbstractHttp11Processor process
信息: 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
    at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:192)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1028)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

前台的请求及报错如下:


Failed to load resource: the server responded with a status of 400 (Bad Request)


http://localhost:8080/XXX/formshow/show.jsp?formId=1222&processFormType=CREATE&formUsage=INPUT&initData={%22flowId%22:%22180206172500073%22,%22flowTypeId%22:%228%22,%22flowType%22:%22WFM%22,%22processNameEn%22:%22com.inspur.plugins.ge.process.GenerateElectricity%22,%22processNameZh%22:%22GE%22,%22processPluginName%22:%22ge%22,%22formType%22:%22JSP%22,%22version%22:%221.1.1%22,%22jspformService%22:%22generateElectricityCreateJspFormService%22}

问题分析:

错误代码 400 请求参数有误

升级tomcat之后就出现了这个问题,Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986,也就是说我们的请求中用了无效的字符。查看RFC规范知,url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~四个特殊字符以及保留字符( ! * ’ ( ) ; : @ & = + $ , / ? # [ ] ) (26*2+10+4+18=84)这84个字符.而我们的请求中出现了{}大括号,所以tomcat报错.

解决办法(四种):

  1. 替换url请求。不用{}
  2. 对请求编码解码。 UrlDecode、UrlEncode
  3. 配置Tomcat对字符的支持 (见下文)
  4. 更换Tomcat版本 (注,Tomcat从 7.0.73, 8.0.39, 8.5.7 版本后添加了对Url的限制。)

    • 配置tomcat支持|{}等字符的方法是:在 catalina.properties中添加 tomcat.util.http.parser.HttpParser.requestTargetAllow=|{} 但是只支持7.0.76, 8.0.42, 8.5.12 之后的版本(这些版本之后支持设置上述属性)

    • 注,Tomcat从 7.0.73, 8.0.39, 8.5.7 版本后添加了对Url的限制。


参考资料:
https://tomcat.apache.org/
https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters
https://stackoverflow.com/questions/41053653/tomcat-8-is-not-able-to-handle-get-request-with-in-query-parameters/44005213#44005213

http://www.cnblogs.com/hark0623/p/6977737.html

http://blog.csdn.net/mk900715/article/details/67637317
http://blog.csdn.net/laokaizzz/article/details/53737080

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值