gpt4 book ai didi

http - 如何在 Reactor Netty 客户端中使用简单的 HTTP 代理?

转载 作者:可可西里 更新时间:2023-11-01 17:18:53 28 4
gpt4 key购买 nike

我正在尝试使用一个简单的 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)请求?

最佳答案

    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();

关于http - 如何在 Reactor Netty 客户端中使用简单的 HTTP 代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52198331/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com