private static final String baseRefer = "http://bbs.**.**.**/forum.php?mod=viewthread&tid=";
private static final String yourCookeie = "Q8qA_2132_saltkey=**; Q8qA_2132_lastvisit=****3699;";
public static void main(String[] args) {
int startId = 774210;
for (int i = 0; i < 100; i++) {
postMessage(startId);
startId++;
}
}
public static void postMessage(int id) {
if (!isExist(id)) {
return;
}
String tmpPath = baseRefer + id;
StringBuilder path = new StringBuilder(tmpPath);
Map<String, String> mapData = new LinkedHashMap<String, String>();
mapData.put("mod", "post");
mapData.put("action", "reply");
mapData.put("replysubmit", "yes");
mapData.put("infloat", "yes");
mapData.put("handlekey", "fastpost");
mapData.put("inajax", "1");
mapData.put("message", "友情帮顶了");
mapData.put("formhash", "86ec5d81");
try {
for (Map.Entry<String, String> mapEnt : mapData.entrySet()) {
path.append("&");
path.append(mapEnt.getKey() + "=");
path.append(URLEncoder.encode(mapEnt.getValue(), "UTF-8"));
}
URL url = new URL(path.toString());
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length",
String.valueOf(path.length()));
con.setRequestProperty(
"User-Agent",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");
con.setRequestProperty("Cookie", yourCookeie);
con.setDoOutput(true);
OutputStream outStr = con.getOutputStream();
outStr.write(path.toString().getBytes());
if (con.getResponseCode() == 200) {
InputStream inputStr = con.getInputStream();
String info = new String(StreamTool.read(inputStr), "UTF-8");
System.out.println("在id=" + id + "成功发帖!");
try {
Thread.sleep(20 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}