0

I want to redirect user when page is opened and POST param. I tried this:

@PostMapping(value = "/redirect/{token}"})
  public ModelAndView handleRedirectMessage(@PathVariable("token") String token,
          @RequestBody Transaction transaction, HttpServletRequest request) throws Exception {

        String post_param = "some_payload";
        return new ModelAndView("redirect:" + url); 
  }

Is it possible to redirect the user and POST some param?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • 1
    An HTTP redirect always results in a GET request. You can't POST using a redirect. – Ivar Jun 14 '19 at 21:47

1 Answers1

0

For example, you have

@GetMapping("/sample_request_mapping_path")
public ModelAndView something() {
    //...
}

revise it to

@PostMapping(value = "/foo"})
public ModelAndView handleRedirectMessage(@PathVariable("token") String token, @RequestBody Transaction transaction, HttpServletRequest request) throws Exception {
    String post_param = "some_payload";
    return "redirect:/sample_request_mapping_path"; 
}
Vy Do
  • 46,709
  • 59
  • 215
  • 313