我们有以下代码与我们的网站交谈,我们在HttpClient级别设置了超时阈值,以确保“我们不会等待很长时间才能获得响应。”。代码是否足以满足上述要求?我们还需要为HttpHead方法设置额外的超时设置吗?
HttpClient httpclient = new DefaultHttpClient();
// the time it takes to open TCP connection.
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, this.timeout);
// timeout when server does not send data.
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, this.timeout);
// the head method
HttpHead httphead = new HttpHead(url);
HttpResponse response = httpclient.execute(httphead);