この記事では、JavaがHTTP Get Post RequestsとCampus BBSの自動応答関数を参照してシミュレートしています。特定のコンテンツは次のとおりです
デザインのアイデア
投稿リンクのコレクションを見つけて、最後に数を変更すると、別の投稿を取得できます
投稿が再び削除されるのを防ぎ、投稿が存在するかどうかを判断します
このコレクションを繰り返し、各リンクに返信するための投稿リクエストを行います
キーポイント
注記:
コード
コードは比較的簡単です。予防策は、あなた自身のクッキーを見つけることです。 yourcookieを割り当てて、yourcookieをひもで締め、直接実行します。
主なことは、投稿が存在するかどうかを判断することです。これはGETリクエストであり、投稿で返信を送信します。返信メッセージは、mapdata.put( "message"、 "Friendly Alt")で「Friendly Alt」としてハードコードされています。
java.io.io.bytearrayoutputStream; Import java.io.ioexception; Import java.io.inputStream; import java.io.outputStream; Import java.io.unsupportedencodingception; Import java.net.httpurlConnection; import.net.net.net.net.net.net.net.net.net.net.net.net.net.net.net.net.net.net.net.malformed.net.net.net.net.net.net.net.net.net java.net.urlencoder; Import java.util.linkedhashmap; import java.util.map; public final string baseRefer = "http://rs.xidian.edu.cn/forum.php?mod = viewth&tid =";プライベート静的な最終文字列yourcookie = "q8qa_2132_saltkey = g1njjj3o; q8qa_2132_lastvisit = 1438243699; q8qa_2132_lastcheckfeed = 256730%7c1438252008; Q8QA_2132_AUTH = E11AEHHXPLGTYPFDK72YJZEGJHL1V70CUXXDTJ71VBU2DYUHH%2BQHW3PGOJHSFXFJBVGNSVYFG1V%2BQLD0LT8LT8KG6J%2B40W0; Q8QA_2132_ST_T = 256730%7C1438571068%7C51F8A322985E44F65FF1143329E6779AA; Q8QA_2132_MYREPEAT_RR = R0; TJPCTRL = 1438781938176; Q8QA_2132_ST_P = 256730%7C143878124%7C7A73EF608DC3CAF733308D63639B3BD0; Q8QA_2132_SID = ZNFQQN; public static void main(string [] args){int startid = 774210; //(int i = 0; i <100; i ++){postmessage(startid); startid ++; }} 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 + "投稿は存在するか、削除されました!"); 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(); } trueを返します。 } 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( "in id =" + id + "に正常に投稿!"); try {thread.sleep(20 * 1000); } catch(arturnedexception e){// todo auto-fenated catch block e.printstacktrace(); }}} catch(unsupportedencodingexception e){// todo auto-enerated 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)スロー例外{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(); }}複製図
上記はこの記事のすべての内容です。すべての人の学習に役立ち、投稿への自動返信を可能にすることを願っています。