3

我正在尝试使用一个简单的 HTTP 代理在外部缓存响应。我尝试了以下代码段:

public static void main(String[] args) {
  HttpClient httpClient = HttpClient.builder().options(httpOptions -> {
    httpOptions.proxy(proxyOptions -> proxyOptions
        .type(Proxy.HTTP)
        .address(InetSocketAddress.createUnresolved("localhost", 7000))
    );
  }).build();
  String url = "http://httpbin.org/get";
  HttpClientResponse response = httpClient.get(url).block();
  System.out.println(response == null ? "null" : response.status().code());
}

...但结果是客户端从一个CONNECT命令开始,创建一个 TCP 隧道。当我使用 时curl,我会执行以下操作:

curl "http://httpbin.org/get" -x "localhost:7000"

...它只是向代理发出一个常规的 HTTP 请求。

我的问题:如何使用 Raector-Netty 向CONNECT代理发出常规(非基于)请求?

4

1 回答 1

1
    ReactorClientHttpConnector connector = new ReactorClientHttpConnector(options ->
            options.httpProxy(addressSpec -> {
                return addressSpec.host("http://proxy_server").port(proxy_port); }));

    webClient = WebClient.builder()
                         .clientConnector(connector)
                         .baseUrl(baseUrl)
                         .build();
于 2019-01-21T19:48:30.893 回答