Tomcat7.x异常:java.lang.IllegalArgumentException

服务器在响应Http请求的时候,出现下面的异常信息:

异常

2017-11-2 9:25:16 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:189)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1000)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:619)

在网上查了一些资料,了解到这是由于tomcat的新版本增加了一个新特性,就是严格按照 RFC 3986规范进行访问解析,而 RFC 3986规范定义了Url中只允许包含英文字母(a-zA-Z)、数字(0-9)、-_.~4个特殊字符以及所有保留字符(RFC3986中指定了以下字符为保留字符:! * ’ ( ) ; : @ & = + $ , / ? # [ ])。最新的tomcat6 7 8 都有这个问题。

我使用的Url请求里面,请求参数含有JSON字符串,字符串里包含“{”、“}”等特殊字符,就会出现上面的异常。通过URLEncoder对JSON字符串进行UTF-8编码,就不会出现这个问题了。

原文地址:https://www.cnblogs.com/lishbo/p/9956029.html