【发布时间】:2021-03-16 14:29:42
【问题描述】:
这是我的代码
import jodd.http.*;
import jodd.http.net.*;
public class JoddQuestion {
public static void main(String[] args) {
SocketHttpConnectionProvider connectionProvider = new SocketHttpConnectionProvider();
ProxyInfo proxyInfo = ProxyInfo.httpProxy("xxxx", xx, "xxxx", "xxxx");
connectionProvider.useProxy(proxyInfo);
String url = "http://www.google.com";
HttpResponse response = HttpRequest.get(url).open(connectionProvider).connectionTimeout(1000).timeout(1000).followRedirects(true).send();
System.out.print(response.bodyText());
}
}
Google 网站在中国被防火墙阻止。不设置代理,运行程序,connectionTimeout 有效。
HttpResponse response = HttpRequest.get(url).connectionTimeout(1000).timeout(1000).followRedirects(true).send();
但是,设置代理后,connectionTimeout 不起作用,程序只是继续尝试。
HttpResponse response = HttpRequest.get(url).open(connectionProvider).connectionTimeout(1000).timeout(1000).followRedirects(true).send();
【问题讨论】:
标签: http proxy jodd connect-timeout