springboot怎么转发http请求?

比如 http://localhost:9100/test.do/localhost:9101/account/login.do?account=xxx&pwd=xxx

我访问 localhost:9100/test.do,转发到任意一个地址的任意一个接口,url要怎么写,转发代码要怎么写?

转发服务器和目标服务器都是我自己写的代码。

补充:目标服务是不对外暴露的,所以不能用重定向。

https://blog.csdn.net/qq_29777207/article/details/112293708

你看看这篇文章呢,我觉很符合你的要求,用 springboot 实现 nginx 的代理功能

mvc该怎么转发就怎么转发!和springboot无关😒

目标服务和转发服务是两个不同的服务?

通过你的描述,我以以下条件为前提

1.转发服务和目标服务不是同一个服务

2.http请求发送到转发服务,转发服务解析url或其他数据,将转发到目标服务器

有两个处理方法:

1.使用response进行重定向,可以使用如下代码

ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse();

2.返回string

return “redirect:url”

url要完整的url :

例如 url=http://www.baidu.com