How to add body using RedirectView / ModelAndView in Spring MVC

482 Views Asked by At

I'm trying to redirect post request to another post request with parameters inside body instead of query params.

@RequestMapping(value = "/redirect/{redirect_uri}", method = RequestMethod.POST, produces = {MediaType.APPLICATION_JSON_VALUE})
public ModelAndView redirect(@PathVariable("redirect_uri") String redirectURI) {
    RedirectView redirect = new RedirectView(redirectURI);
    redirect.setStatusCode(HttpStatus.PERMANENT_REDIRECT); 
    redirect.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    redirect.addStaticAttribute("key1", "value1");
    redirect.addStaticAttribute("key2", "value2");
    ModelAndView modelAndView = new ModelAndView(redirect);
    
    return modelAndView;
}

I added static attributes, but they were added as query params and not in the body. Is there a way to add the values as body?

TIA.

0

There are 0 best solutions below