如何在asynchttpclient中禁用每个请求的代理?

guicsvcw  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(242)

代码如下:

var config = Dsl.config();
var proxy = Dsl.proxyServer("10.1.2.3", 1081);
proxy.setProxyType(ProxyType.SOCKS_V5);
config.setProxyServer(proxy); // Set default proxy globally
var client = Dsl.asyncHttpClient(config);

client
    .prepareGet("https://httpstat.us/200")
    .execute()
    .toCompletableFuture()
    .thenAccept(r -> System.out.println("with proxy: " + r.getResponseBody()))
    .join();

client
    .prepareGet("https://httpstat.us/200")
    .setProxyServer((ProxyServer) null) // I expected it will disable proxy for this particular request
    .execute()
    .toCompletableFuture()
    .thenAccept(r -> System.out.println("without proxy: " + r.getResponseBody()))
    .join();

我原以为第二个请求会在没有代理的情况下执行。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题