private String valueOf(String url, String param,String token) throws IOException {
String result;
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response;
HttpPost httpPost = new HttpPost(url);
if(null != token && token.length() > 0){
httpPost.setHeader("token", token);
}
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000)
.setConnectTimeout(15000)
.setConnectionRequestTimeout(15000)
.build();
StringEntity stringEntity = new StringEntity(String.valueOf(param), "UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
httpPost.setConfig(requestConfig);
response = httpClient.execute(httpPost);
result = EntityUtils.toString(response.getEntity(), "UTF-8");
return result;
}
String data = this.getAllDevice("这里是url",token);
private String getAllDevice(String url, String param) throws IOException {
String result;
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response;
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("token", param);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000)
.setConnectTimeout(15000)
.setConnectionRequestTimeout(15000)
.build();
StringEntity stringEntity = new StringEntity(String.valueOf(param), "UTF-8");
stringEntity.setContentType("application/json");
httpPost.setEntity(stringEntity);
httpPost.setConfig(requestConfig);
response = httpClient.execute(httpPost);
result = EntityUtils.toString(response.getEntity(), "UTF-8");
JSONObject jsonobject = JSONObject.parseObject(result);
String data = jsonobject.getString("data");
return data;
}