gpt4 book ai didi

java - 有一种方法可以设置 HTTPGet Apache 连接拒绝时间吗?

转载 作者:行者123 更新时间:2023-11-30 06:43:07 26 4
gpt4 key购买 nike

我想要获取网页,但如果返回连接被拒绝,我只想等待 1 秒

我的代码:

final DefaultHttpClient client = HTTPSHelper.getClientThatAllowAnyHTTPS(connectionManager);
client.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.BROWSER_COMPATIBILITY);

client.getParams().setParameter("http.socket.timeout", 1000);
client.getParams().setParameter("http.connection.timeout", 1000);
client.addRequestInterceptor(new RequestAcceptEncoding());
client.addResponseInterceptor(new ResponseContentEncoding());

final HttpGet get = new HttpGet(url.getUrl());
final HttpResponse resp = this.httpClient.execute(get, localContext);

当返回连接拒绝时,我必须等待很长时间...有没有办法指定等待连接拒绝的时间?谢谢

最佳答案

您可以通过以下方式设置连接超时:

final HttpParams p = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(p, 1000);
client = new DefaultHttpClient(httpParams) ;

关于java - 有一种方法可以设置 HTTPGet Apache 连接拒绝时间吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44074300/

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