实现
@GetMapping("/get001")
public AjaxResult get001() throws IOException {
System.out.println("开始进入接口");
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append( Post请求地址 )
.append("?")
.append("orgGridEvent.id="+"6")
.append("&address="+"dizhi")
.append("&contentText="+"contentText")
.append("&orgGridEvent.departmentNo=" + "371423102");
String url = stringBuffer.toString().replaceAll(" ", "%20");
System.out.println("开始进入post了");
JSONObject jsonObject = EonUtils.doPostForUrl(url);
System.out.println(jsonObject);
return null;
}
Post工具类
public static JSONObject doPostForUrl(String url){
JSONObject jsonObject = null;
String result = "";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
try {
HttpResponse response = httpClient.execute(httpPost);
result = EntityUtils.toString(response.getEntity());
jsonObject = JSONObject.fromObject(result);
return jsonObject;
}catch (Exception e){
e.printStackTrace();
jsonObject = JSONObject.fromObject(result);
return jsonObject;
}
}