public JSONObject queryList(int pageSize, int pageNo) throws URISyntaxException {
String url = "http://127.0.0.1/test/v1/service/list";
CloseableHttpClient client = HttpClients.createDefault();
URIBuilder uriBuilder = new URIBuilder(url);
uriBuilder.setParameter("pageNo", String.valueOf(pageNo))
.setParameter("pageSize", String.valueOf(pageSize))
.setParameter("serviceName", serviceName);
HttpGet httpGet = new HttpGet(uriBuilder.build());
CloseableHttpResponse response = null;
try {
response = client.execute(httpGet);
if (response.getStatusLine().getStatusCode() == 200) {
HttpEntity httpEntity = response.getEntity();
String content = EntityUtils.toString(httpEntity, "utf8");
if (content != null) {
return JSONObject.parseObject(content);
}
}
} catch (IOException | NacosException e) {
e.printStackTrace();
} finally {
try {
assert response != null;
response.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
http get请求带参数
最新推荐文章于 2024-10-14 14:00:00 发布