后台报错如下

java.lang.IllegalArgumentException: Invalid character found in the request target [/mes/sys/files/getImgBytes?url=\mesFile\9d61397c-dafc-479a-b86c-288d06627f91_f58f86fc-3497-4081-b9b3-897dbc610963.png ]. The valid characters are defined in RFC 7230 and RFC 3986 at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:494) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:269) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1723) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

错误分析

从错误信息来看,问题出在请求的目标路径中包含了非法字符。根据RFC 7230和RFC 3986的规定,URL中的某些字符是不允许直接使用的,例如空格、反斜杠(\)等。我的请求路径中包含了一个反斜杠(\mesFile\96609415-5070-4de9-b718-a1e478abff6b_f58f86fc-3497-4081-b9b3-897dbc610963.jfif),这在URL中是不合法的。

解决方案

在前段请求后台接口时把图片路径用encodeURIComponent进行编码 image.png