DefaultHttpClient已经被标注为deprecated,使用CloseableHttpClient代替怎么写啊?
public static JSONObject doGetStr(String url) { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpGet = new HttpGet(url); JSONObject jsonObject = null; try { HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { String result = EntityUtils.toString(entity, "UTF-8"); jsonObject = JSONObject.fromObject(response); } } catch (IOException e) { e.printStackTrace(); } return jsonObject; }
我这么写得到的entity根本不是想要的