public static void main(String[] args) {
CloseableHttpClient httpclient = HttpClientBuilder.create().build();
HttpPost hp = new HttpPost("http://192.168.1.1");
StringEntity entity2;
try {
entity2 = new StringEntity("{\"method\":\"do\",\"login\":{\"password\":\"vxcTrV4u9TefbwK\"}}");
hp.setEntity(entity2);
CloseableHttpResponse response = httpclient.execute(hp);
//System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
Matcher m = Pattern.compile("\"stok\":\"(.+?)\"").matcher(EntityUtils.toString(response.getEntity(), "utf-8"));
if(m.find()){
HttpPost hp2 = new HttpPost("http://192.168.1.1/stok="+m.group(1)+"/ds");
entity2 = new StringEntity("{\"network\":{\"change_wan_status\":{\"proto\":\"pppoe\",\"operate\":\"disconnect\"}},\"method\":\"do\"}");
hp2.setEntity(entity2);
response = httpclient.execute(hp2);
System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
Thread.sleep(2000);
HttpPost hp3 = new HttpPost("http://192.168.1.1/stok="+m.group(1)+"/ds");
entity2 = new StringEntity("{\"network\":{\"change_wan_status\":{\"proto\":\"pppoe\",\"operate\":\"connect\"}},\"method\":\"do\"}");
hp3.setEntity(entity2);
response = httpclient.execute(hp3);
System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));
Thread.sleep(5000);
System.out.println("iiiiiiiii");
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}