【问题标题】:How to use a simple HTTP proxy with Reactor Netty client?如何在 Reactor Netty 客户端中使用简单的 HTTP 代理?
【发布时间】:2019-02-11 09:04:56
【问题描述】:

我正在尝试使用简单的 HTTP 代理在外部缓存响应。我尝试了以下sn-p:

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 的)请求?

【问题讨论】:

    标签: http netty http-proxy reactor-netty


    【解决方案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();
    

    【讨论】:

    • 您是否检查了实际流量(例如使用 WireShark)以查看它是否使用 CONNECT?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 2016-05-09
    • 1970-01-01
    • 2022-08-20
    相关资源
    最近更新 更多