记录使用emqx http api 踢除指定客户端
CloseableHttpClient httpClient = HttpClients.createDefault();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(35000).setConnectionRequestTimeout(35000).setSocketTimeout(60000).build();
String authString = "admin".trim() + ":" + "public".trim();
String authStringEnc = Base64.getEncoder().encodeToString(authString.getBytes());
String url = "http://localhost:18083/api/v4/clients/" + "20012001";
LogUtil.info("url=" + url);
HttpDelete httpDelete = new HttpDelete(url);
httpDelete.setHeader("Authorization", "Basic " + authStringEnc);
httpDelete.setHeader("Content-type", "application/json");
httpDelete.setHeader("DataEncoding", "UTF-8");
httpDelete.setConfig(requestConfig);
CloseableHttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpDelete);
HttpEntity entity = httpResponse.getEntity();
String result = EntityUtils.toString(entity);
LogUtil.info("result=" + result);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (httpResponse != null) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|