Java 有效字符在 RFC 7230 和 RFC 3986 中定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/54287922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:00:13  来源:igfitidea点击:

The valid characters are defined in RFC 7230 and RFC 3986

javatomcat8

提问by Leandy

My program throws this exception online,I know the reason why it is wrong. My question is how do I find the wrong place,The Java cannot catch the location of this exception. How do I get additional information about this exception,For example, the API for this error requested address.

我的程序在线抛出这个异常,我知道它出错的原因。我的问题是如何找到错误的地方,Java 无法捕获此异常的位置。如何获取有关此异常的其他信息,例如此错误的 API 请求地址。

The error message is as follows:

错误信息如下:

2019-01-18  07:49:23.076 [http-nio-127.0.0.1-8081-exec-96] INFO  org.apache.coyote.http11.Http11Processor - 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.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:484)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:684)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1471)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

回答by Torben

The error message says "Invalid character found in the request target". This means the HTTP client sent a request for a resource that had an invalid characters in it. The server can not parse the request because the request did not adhere to the HTTP protocol specifications.

错误消息显示“在请求目标中发现无效字符”。这意味着 HTTP 客户端发送的资源请求中包含无效字符。服务器无法解析请求,因为该请求不符合 HTTP 协议规范。

This is a client problem. Fix the client.

这是客户端问题。修复客户端。

If it is a public server, maybe someone is trying to break in by sending malformed requests (it's common).

如果它是公共服务器,则可能有人试图通过发送格式错误的请求来闯入(这很常见)。

回答by Dani

If you use an upper version of Tomcat 8.5 it throws this exception if the URL path contains '[' and ']'. For older versions, it works.

如果您使用 Tomcat 8.5 的更高版本,如果 URL 路径包含“[”和“]”,则会引发此异常。对于旧版本,它有效。