CloseableHttpClient httpClient = HttpClients.createDefault();// 创建http实例
CloseableHttpResponse response = null;
HttpGet httpGet =new HttpGet(url);
/*httpPost.setHeader("Referer","http://oms.hqygou.com/order/temp/new");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
httpPost.setHeader("X-Requested-With","XMLHttpRequest");
httpPost.setHeader("Cookies",cookies);*/
/*HttpHost proxy =new HttpHost("125.118.79.44", 6666);
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
httpGet.setConfig(config);*/
//RequestConfig config = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000).build();//设置请求和传输超时时间
//httpGet.setConfig(config);
httpGet.setHeader("Connection","keep-alive");
httpGet.setHeader("Content-Type","application/html; charset=UTF-8");
httpGet.addHeader(new BasicHeader("Cookie", cookie));
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity(); //请求类型
//System.out.println(entity.getContentType());//
String content = EntityUtils.toString(entity, "utf-8");
///
response.close();
httpClient.close();
这篇写的更好