In spring mvc, headers = "x-request-with: XMLHttpRequest" in the request do not work?

I have two methods: one must handle the login request issued by JS, the other takes care of the login page.

 @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD},
    headers = "x-requested-with:XMLHttpRequest")
    public @ResponseBody String login() {...}


 @RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD})
    public String getLoginPage() {......}

However, all the login requests seem to be related to the getLoginPage method, whether it has the header "x-request-with: XMLHttpRequest" or not. I doubled the verified http headers, it contains the correct head. Therefore, it seems that Spring is simply ignoring the login method.

I struggled with this for a while, any advice would be greatly appreciated, thanks!

+3
source share
1 answer

headersuses =as a separator:

@RequestMapping(value = "/login", method = {RequestMethod.GET, RequestMethod.HEAD},     
    headers = "x-requested-with=XMLHttpRequest") 
+8
source

Source: https://habr.com/ru/post/1789038/


All Articles