Spring mvc 使用HttpClient的Spring MVC隧道请求
我创建了一个控制器来处理对Spring mvc 使用HttpClient的Spring MVC隧道请求,spring-mvc,httpclient,tunnel,Spring Mvc,Httpclient,Tunnel,我创建了一个控制器来处理对/tunnel的所有请求 这是我的控制器: @Controller @RequestMapping("/tunnel/**") public class TunnelController { @RequestMapping public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { String ur
/tunnel
的所有请求
这是我的控制器:
@Controller
@RequestMapping("/tunnel/**")
public class TunnelController {
@RequestMapping
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException {
String url = request.getRequestURI().substring(request.getContextPath().length() + "/tunnel".length());
System.out.println(url);
CloseableHttpClient client = HttpClientBuilder.create().build();
try {
// inject custom HEADERS
// tunnel the request and the response to other server
} finally {
client.close();
}
}
}
然后,当我向这个控制器请求时,它必须在内部隧道到
如何使用HttpClient将此请求通过隧道传输、克隆请求(头、属性、参数等)并通过隧道传输到其他服务器?为此,您最好使用像nginx这样的反向代理。这就是他们的目的。我需要在执行请求之前注入一些头,比如安全令牌和其他头,所以我不能使用nginx。