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.
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 headerNote: 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 3986at 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)
Best Answer
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.
The workaround would be adding below attributes to http connector port in tomcat server.xml
file
relaxedPathChars="[]|" relaxedQueryChars="[]|{}^\`"<>"
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.
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).
I encountered the same error when sending location of a file in a AJAX GET request.
Since the location had characters which are not recognized. I.e. "C:///" etc, the error was thrown.
The use of encodeURIComponent
helped me fix the issue since it encodes the component.
When you pass the location make sure you add those inside "encodeURIComponent
" method. In my case:
$.ajax({type: "GET",url: 'removeFile?removeFilePath=' + encodeURIComponent("C:///YO/Ed/PO/")data: {},dataType: 'json',
Used Tomcat v8.5, below update in server.xml works for me since '<>' is not allowed
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^`'"/>