Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use spring mvc controller make a post request?

How to make a controller method to redirect to other site with a post request?

    @RequestMapping("/link)
    public RedirectView  goToTheSite(ModelMap model) {
        model.put("name", "wow");
        return new RedirectView("https://www.thesite.com", true, false, false);

    }

but, this is not working, How to do that in right way?

like image 458
libo Avatar asked Jan 25 '26 04:01

libo


1 Answers

How to make a controller method to redirect to other site with a post request?

Redirect means you telling browser to make a GET request, There is no out of the box feature in Spring MVC to make POST request from controller.

How to do that in right way?

Use Apache HTTP client:

Request.Post("https://www.thesite.com/login")
    .bodyForm(Form.form().add("username",  "vip").add("password",  "secret").build())
    .execute().returnContent();
like image 123
Abhishek Nayak Avatar answered Jan 28 '26 18:01

Abhishek Nayak