前言
通过iObjects Java调用iServer的rest api删除iServer上已发布的工作空间
一、创建PUT请求方式实例
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPut httpPut = new HttpPut(deleteUrl + "?token=" + token);
注: 1、此处deleteUrl 固定为http://ip:端口/iserver/manager/workspaces.rjson 2、token为iServer中的令牌
二、构造消息实体
1.构造
String params = "{\"workspaceConnectionInfo\":" + "\"" + urlToRead.replaceAll("\\\\", "/") + "\"" + "}";
JSONObject jsonObject = JSONObject.parseObject(params);
System.out.println(params);
StringEntity entity = new StringEntity(jsonObject.toString(), Charset.forName("UTF-8"));
注:此处urlToRead为工作空间在本地的绝对路径
2.设置编码格式并把消息实体塞进去
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPut.setEntity(entity);
三、执行http的put请求
CloseableHttpResponse httpResponse;
String result = null;
try {
httpResponse = httpClient.execute(httpPut);
result = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
四、Postman发请求
|