Dieser Artikel teilt Java Simulates http erhalten Postanfragen und Campus BBS Automatische Antwortfunktion für Ihre Referenz. Der spezifische Inhalt ist wie folgt
Designideen
Finden Sie die Sammlung von Postlinks und ändern Sie die Nummer am Ende. Sie können verschiedene Beiträge erhalten
Verhindern, dass die Beiträge erneut gelöscht werden, und stellen Sie fest
Durch diese Sammlung iterieren und eine Postanfrage erstellen, um auf jeden Link zu antworten
Schlüsselpunkte
Notiz:
Code
Der Code ist relativ einfach. Die Vorsichtsmaßnahme ist, Ihren eigenen Keks zu finden. Weisen Sie Ihren Cookie -String Yourcookie zu und führen Sie es direkt aus.
Die Hauptsache ist zu bestimmen, ob der Posten existiert oder nicht. Dies ist eine Get -Anfrage, und senden Sie dann eine Antwort mit Post. Die Antwortmeldung wird als "freundlich geholfen" in MapData.put ("Nachricht", "freundlich geholfen"). Sie können sie ändern
Importieren Sie Java.io.BytearrayoutputStream; Import Java.io.ioxception; Import Java.io.inputStream; Import Java.io.outputStream; Import Java.io.unsupportedencodingException importieren Java.net.httpurlconnection; java.net.urlencoder; import java.util.linkedhashMap; import Java.util.map; öffentliche Klasse inter {private statische String -Basierfer = "http://rs.xidian.edu.cn/forum.php?mod=viewThead&tid="; private statische endgültige String yourcookie = "q8qa_2132_saltkey = g1njjj3o; q8qa_2132_lastvissit = 1438243699; Q8QA_2132_AUTH = e11aeHHXPLGTYPFDK72YJZEGJHL1V70CUXXDTJ71VBU2DYUH%2BQHW3PGOJHSFXFJBVGNSVYFG1V%2BQLD0LT8KG6J%2B40W0; Q8QA_2132_ST_T = 256730%7C1438571068%7C51F8A322985E44F65FF114329E6779A; Q8qa_2132_ulastActivity = d7DEGFMAWG5AGHSHMT%2BWCQ1L91ZNQPEA57P%2F0VT7VHDC8DROUGTT; Q8QA_2132_viitedfid = 72D551D215D110D13D142D22D91D217D548; Q8QA_2132_ViewID = TID_773850; public static void main (String [] args) {int startid = 774210; // Sie müssen ändern (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 ("Inhaltstyp", "Text/html; charset = utf-8"); con.addRequestProperty ("User-Agent", "Mozilla/5.0 (Windows NT 6.1) Applewebkit/537,36 (khtml, wie Gecko) Chrome/38.0.2125.104 Safari/537.36"); con.addrequestProperty ("Referer", "http://t.dianping.com/register"); con.setRequestMethod ("get"); if (con.getResponSCode () == 200) {inputStream inputStr = con.getInputStream (); String info = new String (streamtool.read (inputStr), "utf-8"); if (info.contains ("Entschuldigung, das angegebene Thema existiert nicht oder wurde gelöscht oder wird überprüft")) {System.out.println ("id =" + id + "Der Beitrag existiert oder wurde gelöscht!"); false zurückgeben; }}} catch (fehl Formaledurlexception e) {// Todo automatisch generierter Catch-Block e.printstacktrace (); } catch (ioException e) {// Todo automatisch generierter Catch-Block e.printstacktrace (); } catch (Ausnahme e) {// Todo automatisch generierter Block E. printstacktrace (); } Return true; } public static void postMessage (int id) {if (! isexist (id)) {return; } String tmppath = BasieRefer + id; StringBuilder path = new StringBuilder (tmppath); Karte <String, String> mapData = new LinkedHashMap <String, String> (); mapData.put ("mod", "post"); MapData.put ("Aktion", "Antwort"); MapData.put ("ReplySubmit", "Ja"); MapData.put ("Beim", "Ja"); MapData.put ("Handy", "Fastpost"); mapData.put ("inajax", "1"); MapData.put ("Nachricht", "Freundschaftsunterstützung"); 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-Typ", "Anwendung/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, wie 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.getResponSCode () == 200) {inputStream inputStr = con.getInputStream (); String info = new String (streamtool.read (inputStr), "utf-8"); System.out.println ("in id =" + id + "erfolgreich veröffentlicht!"); try {thread.sleep (20 * 1000); } catch (InterruptedException e) {// Todo automatisch generierter Catch-Block e.printstacktrace (); }}} catch (nicht supportedenCodingException e) {// Todo automatisch generierter Catch-Block e.printstacktrace (); } catch (fehl Formaledurlexception e) {// Todo automatisch generierter Catch-Block e.printstacktrace (); } catch (ioException e) {// Todo automatisch generierter Catch-Block e.printstacktrace (); } catch (Ausnahme e) {// Todo automatisch generierter Block E. printstacktrace (); }}} class streamtool {public static byte [] read (InputStream InputStr) löst eine Ausnahme aus {bytearrayoutputStream outstr = new bytearrayoutputStream (); // TODO Auto-generierter Methode Stub Byte [] Buffer = New Byte [1024]; int len = 0; while ((len = inputstr.read (puffer))! = -1) {outstr.write (buffer, 0, len); } inputStr.close (); return overstr.tobytearray (); }}Reproduktionsdiagramm
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und automatische Antwort auf Beiträge ermöglichen.