JAVA HttpClient发送消息
1. 定义Http param消息体
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class Req{
private String id;
private JSONObject ehrNormalResultEntity;
// JSONObject 格式,实例化时需要用JSONObject.parseObject("")转义
}
2. HttpClient
public JSONObject apply(String param, String token) throws Exception {
String url = "http://; // url
// String response = HttpClient.sendPostDataByJson(url, param,token); //发送Post请求
String response = HttpClient.sendGetDataAndToken(url,param,token); //发送get请求
JSONObject result = JSONObject.parseObject(response);
return result;
}
3. 构建实体HttpClient并发送,获取返回结果
Req req=Req .builder()
.id(normalId)
.comment("")
.approveStatus(1)
.build();
String param = JSON.toJSONString(req);
JSONObject res = ehrNormalService.apply(param,ApproverToken);