让我们考虑一下我有两个 Web 应用程序 A 和 B 的情况
初始数据到达 A,我有下一个 Controller :
@RestController
public class restController {
@RequestMapping(path = "/testA", method = RequestMethod.POST)
public final void test(*inputdata*) { "redirect POST to B app" }
}
此数据必须发送到应用程序 B:
@RestController
public class restController {
@RequestMapping(path = "/testB", method = RequestMethod.POST)
public final void test(*inputdata*) { 'some logic' }
}
并且逻辑结果必须发送回 A 应用。
通信必须以 RESTful 格式进行。
据我通过“谷歌搜索”发现,Spring 无法做到这一点,我必须创建自定义“POST”方法,是这样吗?因为这个链接http://www.baeldung.com/spring-redirect-and-forward包含有关“重定向 HTTP POST 请求”的信息,但我无法理解他们使用它的方式。
谢谢!
最佳答案
redirect
转到用户浏览器,然后转到重定向的 URL。它将始终作为 GET
请求进行。在您的情况下,您必须使用 A 的 httpclient
(RestTemplate) 从 A 调用应用程序 B。我不确定这是否会满足您的要求。一个
另一种方法可能是发送一个页面作为 A 请求的响应,并让该页面提交一个 ajax 请求,这是一个 POST 请求,但我想既然你想要 REST 上的所有内容,这可能不是你想要的。
关于java - 如何在 Spring Boot 中将 POST 请求从一个 Web 应用程序正确转发到另一个 Web 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49912752/