1

我们有以下代码可以与我们的网站通信,并且我们在 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);
4

0 回答 0