欢迎使用CSDN-markdown编辑器

来源:互联网 发布:mac散热器声音大怎么办 编辑:程序博客网 时间:2024/06/06 11:51

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);        }    } catch (Exception e) {        // TODO Auto-generated catch block        e.printStackTrace();    }}
0 0