Encoded slash (/) with Spring RequestMapping path param gives HTTP 400

前端 未结 9 773
陌清茗
陌清茗 2020-12-05 00:10

This is not a duplicate referenced question, because it is Spring specific. Whoever added that (3 years after the fact!) didn\'t bother to read the question or comment

相关标签:
9条回答
  • 2020-12-05 00:48

    For spring boot application this worked for me..

    Version 1 Add

    org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
    

    to your application.properties file

    Version 2 run your spring boot application like this.

    static void main(String[] args) {
        System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
        SpringApplication.run this, args
    }
    

    Version 3 or run your java application with -Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

    This fixed %2F encoded slash path variable for me.

    0 讨论(0)
  • 2020-12-05 00:49

    We just ran into this issue at my office, we did what was suggestion above from what Solubris said where you put it in a query param. The only additional requirement is that the data could have an '&' as well, which would mess up the query param. All we had to do is encode the text before it is sent in the URL and even '&' were filtered out.

    0 讨论(0)
  • 2020-12-05 00:54

    This could be your answer: urlencoded Forward slash is breaking URL

    I would suggest not putting that in the path, move it to a request param instead.

    Work around:

    You could change the RequestMapping to

    @RequestMapping(value = "/ws/stuff/lookup/resourceId/**", method = RequestMethod.GET) 
    

    and then parse the path variables manually from the request object.

    0 讨论(0)
提交回复
热议问题