国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服務器之家 - 編程語言 - JAVA教程 - Java模擬HTTP Get Post請求實現論壇自動回帖功能

Java模擬HTTP Get Post請求實現論壇自動回帖功能

2020-06-10 11:45anquye200 JAVA教程

這篇文章主要介紹了Java模擬HTTP Get Post請求實現論壇自動回帖功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近想自動發(fā)帖回帖,拿某論壇試驗了一下,發(fā)現可行,不過后續(xù)沒有再使用,以免影響論壇正常運行。

1、帖子鏈接的格式為
http://bbs.***.***.**/forum.php?mod=viewthread&tid=774210

最后面774210數字變化, 就可以得到不同的帖子

2、防止帖子發(fā)表會又被刪了的情況, 進行判斷帖子是否存在

3、遞增后面的 id 數字, 對每個鏈接做回帖的 POST 請求

重難點

回帖需要用戶登錄信息
一種是利用Cookie
另一種是進行模擬登錄

本文采用前者

判斷 url 對應的帖子是否存在
有可能用戶發(fā)了帖子,比如 url 為 http://bbs.***.***.**/forum.php?mod=viewthread&tid=774200

后來該帖子用戶刪除了或者被管理員刪除了,雖然帖子不在了,但是該 tid=774200 還是存在的

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public static boolean isExist(int id) {
 String tmpPath = baseRefer + id;
 URL url;
 try {
 url = new URL(tmpPath);
 HttpURLConnection con = (HttpURLConnection) url.openConnection();
 con.addRequestProperty("Content-Type", "text/html; charset=UTF-8");
 con.addRequestProperty(
  "User-Agent",
  "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.104 Safari/537.36");
 con.addRequestProperty("Referer", "http://t.dianping.com/register");
 con.setRequestMethod("GET");
 if (con.getResponseCode() == 200) {
  InputStream inputStr = con.getInputStream();
  String info = new String(StreamTool.read(inputStr), "UTF-8");
  if (info.contains("抱歉,指定的主題不存在或已被刪除或正在被審核")) {
  System.out.println("id=" + id + "帖子存在或已被刪除!");
  return false;
  }
 }
 } catch (MalformedURLException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
 return true;
}

模擬發(fā)帖
代碼比較簡單,注意事項是找到自己的Cookie,賦給String yourCookeie

用post發(fā)送一個回帖,回帖信息在 mapData.put("message", "友情幫頂了") 中

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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; // you need change
 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 + "成功發(fā)帖!");
  try {
  Thread.sleep(20 * 1000);
  } catch (InterruptedException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  }
 }
 } catch (UnsupportedEncodingException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (MalformedURLException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (IOException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } catch (Exception e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }
}

還有一個工具方法,將輸入流轉化為字節(jié)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
class StreamTool {
 public static byte[] read(InputStream inputStr) throws Exception {
 ByteArrayOutputStream outStr = new ByteArrayOutputStream();
 // TODO Auto-generated method stub
 byte[] buffer = new byte[1024];
 int len = 0;
 while ((len = inputStr.read(buffer)) != -1) {
  outStr.write(buffer, 0, len);
 }
 inputStr.close();
 return outStr.toByteArray();
 }
}

效果圖:

Java模擬HTTP Get Post請求實現論壇自動回帖功能

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.alijava.com/simulate-bbs/

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 91亚洲国产精品 | 日韩av电影在线观看 | 中文亚洲字幕 | 在线精品一区 | 99精品国产高清在线观看 | 成人a级片在线观看 | 亚洲精品国产成人 | 国产在线第一页 | 欧美成人免费网站 | 免费的黄视频 | 国产99久久久精品视频 | 欧美午夜精品久久久久久人妖 | 国产在线精品一区二区 | 成人av高清在线观看 | 天天爱天天操 | 国产99久久 | 亚洲电影天堂在线观看 | 午夜操操 | 久久久91精品国产一区二区三区 | 国产在线中文字幕 | 一区二区三区在线播放 | 精品一区二区三区在线视频 | 亚洲国产精品久久 | 国产精品福利在线 | 欧美成人影院 | 一级网站在线观看 | 日韩精品视频在线观看一区二区 | 综合久久99| 99re国产| 99综合在线 | 精品美女久久久 | 日本黄色美女视频 | 精品视频网站 | 欧美精品欧美精品系列 | 久久激情五月丁香伊人 | 成人在线观看网站 | 亚洲成人午夜电影 | 日韩精品久久 | 免费一级欧美在线观看视频 | www欧美 | 久久成人高清 |