1.新建头信息,并设置编码方式
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
2.组装发送的内容,例如我此处发送了一段字符串
HttpEntityentity = new HttpEntity<>(xmlString.toString(),headers); String getRegisterUrl = "172.17.13.133:24680";//发送地址
3.进行发送
RestTemplate restTemplate = new RestTemplate();
try{
restTemplate.postForEntity(getRegisterUrl, entity, String.class);
}catch (Exception e){
logger.error("模拟告警恢复发送 ------------> Deamon失败");
e.printStackTrace();
}
postForEntity 方法有返回值,可通过返回值的状态码判断是否发送成功



