Controller访问接口获得返回值
public String getAllItemInfoByItemID() throws HttpException, IOException{
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
// 创建Get请求
HttpGet httpGet = new HttpGet("http://localhost:8080/CQUExptMgmtSystem/request/ttt1?userid=1");
// 响应模型
CloseableHttpResponse response = null;
HttpEntity responseEntity = null;
try {
// 由客户端执行(发送)Get请求
response = httpClient.execute(httpGet);
// 从响应模型中获取响应实体
responseEntity = response.getEntity();
System.out.println("响应状态为:" + response.getStatusLine());
if (responseEntity != null) {
System.out.println("响应内容长度为:" + responseEntity.getContentLength());
// System.out.println("响应内容为:" + EntityUtils.toString(responseEntity));
String str =EntityUtils.toString(responseEntity);
return str;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {