Spring不处理查询参数数组?productsId [] = 1&productsId [] = 2中的方括号

时间:2019-06-06 20:06:15

标签: spring-mvc tomcat

服务器端的实现是

    @GetMapping
    public List<...> getProductsWithIds(@RequestParam("productsId") Set<Long> productsId) {
        ////....////
    }

它可以与GET HOST/products?productsId=65&productsId=67

一起正常工作

但是,客户端之一向我的服务器GET HOST/products?productsId[]=65&productsId[]=67(方括号)发送以下请求,并且服务器出现以下错误

2019-06-06 21:45:16.598  INFO 10209 --- [nio-8081-exec-1] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request 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:467) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294) ~[tomcat-embed-core-9.0.13.jar:9.0.13]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.13.jar:9.0.13]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) [tomcat-embed-core-9.0.13.jar:9.0.13]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) [tomcat-embed-core-9.0.13.jar:9.0.13]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.13.jar:9.0.13]
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) [na:na]
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [na:na]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.13.jar:9.0.13]
    at java.base/java.lang.Thread.run(Thread.java:844) [na:na]

您知道如何处理带有方括号[]的请求吗?

PS。我也尝试过@RequestParam("productsId[]")-同样的结果

0 个答案:

没有答案