public static String httpGet(String url,String token) throws URISyntaxException {
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse httpResponse ;
String finalString = null;
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("accept", "*/*");
httpGet.setHeader("Accept-Encoding","gzip, deflate");
httpGet.setHeader("Cache-Control","no-cache");
httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
httpGet.setHeader("authorization",token);
System.out.println("发起请求的信息:"+httpGet);
try {
httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
finalString= EntityUtils.toString(entity, "UTF-8");
try {
httpResponse.close();
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
return finalString;
}
|