如何用Java模拟HttpClient中的代理连接



我试图模仿下面的代码,但不成功,谁能建议如何实现这一点?

HttpClient httpClient = HttpClient.create()
.tcpConfiguration(tcpClient -> tcpClient
.proxy(proxy -> proxy
.type(ProxyProvider.Proxy.HTTP)
.host(host)
.port(Integer.parseInt(port))));

ClientHttpConnector clientHttpConnector = new ReactorClientHttpConnector(httpClient);
webClient = WebClient.builder().clientConnector(clientHttpConnector).build();

将创建HttpClient的代码移动到它自己的类中:

interface HttpClientFactory {
HttpClient create();
}
class DefaultHttpClientFactory implements {
HttpClient create() {
return HttpClient.create()
.tcpConfiguration(tcpClient -> tcpCl...
}
}

现在可以模拟HttpClientFactory和它返回的模拟HttpClient