public void doGet(String text) {
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
String ip = environment.getProperty("ip");
String port = environment.getProperty("port");
String url = "http://" + ip + ":" + port + "/search?text=" + text;
HttpGet httpGet = new HttpGet(url);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("内容"+EntityUtils.toString(entity));
String res = EntityUtils.toString(entity);
JSONObject jsonResult = new JSONObject(res);
JSONArray jsonArr = jsonResult.getJSONArray("rows");
for (int i = 0; i < jsonArr.size(); i++) {
JSONObject jObject = jsonArr.getJSONObject(i);
//
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
// 释放资源
try {
response.close();
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
springboot发起get请求
最新推荐文章于 2025-03-10 23:46:59 发布