// 设置超时重定向 private void setTimeOut(HttpRequestBase request, int timeout) { RequestConfig requestConfig = RequestConfig.custom() .setConnectionRequestTimeout(timeout) .setConnectTimeout(timeout) .setSocketTimeout(timeout) .setRedirectsEnabled(true) .build(); request.setConfig(requestConfig); }
/** * 设置请求配置 * * @param clientRequest http client请求 */ private static void setRequestConfig(HttpRequestBase clientRequest) { // 超时配置 int connectionTimeout = Integer.parseInt(PropertyUtil.get("webUtils.http.idleTimeout", "6000"), 10); if (connectionTimeout > 0) { RequestConfig defaultRequestConfig = RequestConfig.custom() .setSocketTimeout(connectionTimeout) .setConnectTimeout(connectionTimeout) .setConnectionRequestTimeout(connectionTimeout) .build(); clientRequest.setConfig(defaultRequestConfig); } }