旧的方法(已被禁用)
CloseableHttpClient httpclient = HttpClients.createDefault(); httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5000); httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,5000);
新的方法
HttpPost httppost = new HttpPost(httpUrl); //设置超时时间为5秒 RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(5000).setConnectTimeout(5000).setSocketTimeout(5000).build(); httppost.setConfig(requestConfig);
时间: 2024-11-10 10:21:31