String response = null;
// 客户端接口请求路径
String url = EspConfig.getClientBaseUrl() + ClientUtil.CLIENT_METHODNAME;
// 创建请求
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
// 配置请求
post.setHeader("Content-Type", "application/json;charset=UTF-8");
StringEntity stringEntity = new StringEntity(JSON.toJSONString(proScheduleVO), "utf-8");
stringEntity.setContentEncoding("utf-8");
stringEntity.setContentType("application/json");
post.setEntity(stringEntity);
try {
// 执行请求获取响应
log.info("=============================================================33333333333333333333333333333333333333");
HttpResponse res = httpclient.execute(post);
log.info("============================================================="+res.getStatusLine().getStatusCode());
if (res.getStatusLine().getStatusCode() == 200) {
response = EntityUtils.toString(res.getEntity());
}
//判断返回是否为空
// 客户端接口请求路径
String url = EspConfig.getClientBaseUrl() + ClientUtil.CLIENT_METHODNAME;
// 创建请求
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
// 配置请求
post.setHeader("Content-Type", "application/json;charset=UTF-8");
StringEntity stringEntity = new StringEntity(JSON.toJSONString(proScheduleVO), "utf-8");
stringEntity.setContentEncoding("utf-8");
stringEntity.setContentType("application/json");
post.setEntity(stringEntity);
try {
// 执行请求获取响应
log.info("=============================================================33333333333333333333333333333333333333");
HttpResponse res = httpclient.execute(post);
log.info("============================================================="+res.getStatusLine().getStatusCode());
if (res.getStatusLine().getStatusCode() == 200) {
response = EntityUtils.toString(res.getEntity());
}
//判断返回是否为空
if(response==null){
throw new NullPointerException("推送失败");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
throw new NullPointerException("推送失败");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
// 转换成返回对象
log.info("============================================================="+response);
JSONObject jsonObj = JSON.parseObject(response);
log.info("============================================================="+jsonObj.get("resultCode").toString());
log.info("============================================================="+response);
JSONObject jsonObj = JSON.parseObject(response);
log.info("============================================================="+jsonObj.get("resultCode").toString());