我想要获取网页,但如果返回连接被拒绝,我只想等待 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/