私は最近、自動的に投稿し、自動的に返信したいと思いました。私はフォーラムで試してみましたが、それが実行可能であることがわかりましたが、フォーラムの通常の運用に影響を与えることを避けるために将来再び使用されていませんでした。
1。投稿リンクの形式はです
http://bbs.***.** .**/forum.php?mod = viewthread&tid = 774210
774210の終わりに数の変更は、さまざまな投稿を取得することで取得できます
2。投稿が再度削除されないようにし、投稿が存在するかどうかを判断します
3。その後ID番号を増やし、各リンクに返信するための投稿リクエストを行います
キーポイント
返信にはユーザーログイン情報が必要です。1つはCookieを使用することです
別の方法は、ログインをシミュレートすることです
この記事では、前者を採用しています
URLの対応するポストが存在するかどうかを判断します
ユーザーが投稿を投稿した可能性があります。たとえば、URLはhttp://bbs.***.**./forum.php?mod = viewthread&tid = 774200です。
その後、投稿のユーザーが管理者によって削除または削除されました。投稿はなくなっていますが、TID = 774200はまだ存在します。
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、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 + "postが存在するか、削除されました!"); falseを返します。 }}} catch(malformedurlexception e){// dodo auto-enerated catch block e.printstacktrace(); } catch(ioException e){// todo auto-fenated catch block e.printstacktrace(); } catch(例外e){// todo auto-enerated catch block e.printstacktrace(); } catch(例外e){// todo auto-enerated catch block e.printstacktrace(); } catch(例外e){// todo auto-enerated catch block e.printstacktrace(); } catch(例外e){// todo auto-enerated catch block e.printstacktrace(); } trueを返します;}投稿のシミュレーション<br />コードは比較的簡単です。予防措置はあなた自身のクッキーを見つけて、yourcookieをひもに割り当てることです
投稿を使用して返信を送信すると、返信メッセージはmapdata.put( "メッセージ"、 "友情ヘルプ")にあります
private static final string baseRefer = "http://bbs.*.*./forum.php?mod = viewthread&tid ="; private static final string yourcookie = ** **; q8qa_2132_lastvisit = ******************* 774210; //(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、geckoのような)chrome/38.0.2125.104 safari/537.36"); con.setRequestProperty( "cookie"、yourcookie); 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(arturnedexception e){// todo auto-fenated catch block e.printstacktrace(); }} catch(unsupportedencodingexception e){// todo auto-fenated catch block e.printstacktrace(); } catch(malformedurlexception e){// dodo auto-enerated catch block e.printstacktrace(); } catch(ioException e){// todo auto-fenated catch block e.printstacktrace(); } catch(例外e){// todo auto-enerated catch block e.printstacktrace(); }}入力ストリームをバイトに変換するツールメソッドもあります
class streamtool {public static byte [] read(inputstream inputstr)throws exception {bytearrayoutputstream outstr = new bytearrayoutputStream(); // TODO自動生成方法スタブバイト[] buffer = new byte [1024]; int len = 0; while((len = inputstr.read(buffer))!= -1){outstr.write(buffer、0、len); } inputstr.close(); retunstr.tobytearray(); }}複製画像:
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。