gpt4 book ai didi

spring-mvc - 如何使用 spring mvc controller 发出 post 请求?

转载 作者:行者123 更新时间:2023-12-03 23:50:06 25 4
gpt4 key购买 nike

如何使 Controller 方法通过发布请求重定向到其他站点?

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

}

但是,这是行不通的,如何以正确的方式做到这一点?

最佳答案

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

重定向意味着您告诉浏览器发出 GET 请求,Spring MVC 中没有现成的功能可以从 Controller 发出 POST 请求。

How to do that in right way?

使用Apache HTTP client :

Request.Post("https://www.thesite.com/login")
.bodyForm(Form.form().add("username", "vip").add("password", "secret").build())
.execute().returnContent();

关于spring-mvc - 如何使用 spring mvc controller 发出 post 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29037270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com