这是我的代码
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());
}
}
谷歌网站在中国被防火墙封锁。在不设置代理的情况下,运行程序,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();