示例:
JSONObject requestParams = new JSONObject();
requestParams.put("母亲姓名", mothername);
requestParams.put("母亲联系电话", mothertelephone);
requestParams.put("母亲证件号码", motheridcard);
requestParams.put("父亲姓名", fathername);
requestParams.put("父亲联系电话", fathertelephone);
requestParams.put("父亲证件号码", fatheridcard);
requestParams.put("家庭住址", house);
requestParams.put("预产期", childbirthdate);
requestParams.put("分娩医院", hospital);
requestParams.put("交费方式", jffs);
requestParams.put("优惠金额", youhui);
requestParams.put("应交", yingjiao);
requestParams.put("实交金额", shijiao);
requestParams.put("样本类型", yangbentype);
// }
//json对象转换成字符串方便传参
String paramsvalue = requestParams.toString();
//测试
// this.getView().showTipNotification("当前选中的是" + paramsvalue);
//接口post请求
CloseableHttpClient httpClient = HttpClients.createDefault();
//header
HttpPost httpPost = new HttpPost(ContractConstants.getCREATEBYTEMPLATE());
httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
httpPost.setHeader("x-qys-accesstoken", ContractConstants.getAPPTOKEN());
Date now = new Date();
long timestamp = DateUtils.dateToTimeStamp(now);
httpPost.setHeader("x-qys-timestamp", timestamp+"");
httpPost.setHeader("x-qys-signature", ContractConstants.getSignature(timestamp));
//body
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.addTextBody("templateid", templateid);
entityBuilder.addTextBody("params", paramsvalue);
entityBuilder.addTextBody("title", TITLE);
HttpEntity entity = entityBuilder.build();
httpPost.setEntity(entity);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
// Handle response here
System.out.println("Response code: " + response.getStatusLine().getStatusCode());
} catch (IOException d) {
d.printStackTrace();
}
![12 12]()
本文链接:https://www.naiteiy.site/index.php/archives/81/