Issue
I have a Controller like this one:
@PostMapping(value = { "/" })
public String home(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
return "redirect:/index.html?xyz=abc";
}
It is redirecting the request to an Angular application and was working as expected. But as soon as I changed the PostMapping annotation to:
@PostMapping(value = { "/", "/{id}" })
It started giving me a 405 error in chrome console as:
Failed to load resource: the server responded with a status of 405 () https://My_IP/index.html?xyz=abc
Can anyone suggest what am I missing here? Would it require a fix on the Java side or the Angular side?
Angular version: 8.1.3
RedirectAttributes are from org.springframework.web.servlet.mvc.support.RedirectAttributes
Solution
After adding the "/{id}" within the @postmapping the system tries to match the get redirect request to the /id itself, as it assumed "index.html" as id. And as it was a get redirect, while the /id was a post request, it gave a 405 error.
I avoided the issue by not using the '/' directly, but adding an API name to it, such as below:
@PostMapping(value = { "/home", "/home/{id}" })
after this, system did not try to match the https://My_IP/index.html?xyz=abc request to /home or /home/id.
Answered By - V.Aggarwal
Answer Checked By - Cary Denson (JavaFixing Admin)