CloseableHttpAsyncClient实现Post方式HTTP异步调用接口
依赖注入
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
var foo = 'bar';
方法处理
public static void attendanceOption(String aaa) throws UnsupportedOperationException, IOException {
try {
CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
client.start();
final HttpPost post = new HttpPost
("http://xxxxxxxxxxxxxxxxxon/update");
JSONObject param= new JSONObject();
param.put("aaa", ""+aaa+"");
post.addHeader("Content-type", "application/json; charset=utf-8");
post.setHeader("Accept", "application/json");
StringEntity stringEntity = new StringEntity(param.toString());
post.setEntity(stringEntity);
try {
client.execute(post, null);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(e);
}
}
调用方法
if(srceenList.size()>0){
try {
ChangeData.attendanceOption(aaa);
} catch (IOException e) {
e.printStackTrace();
}
}