이 기사는 Java를 공유합니다. HTTP Get Post 요청 및 캠퍼스 BBS 자동 응답 기능은 참조를 공유합니다. 특정 내용은 다음과 같습니다
디자인 아이디어
게시물 링크 모음을 찾고 마지막에 번호를 변경하면 다른 게시물을 얻을 수 있습니다.
게시물이 다시 삭제되는 것을 방지하고 게시물이 존재하는지 확인합니다.
이 컬렉션을 통해 반복하고 각 링크에 회신하기위한 게시물 요청을 작성하십시오.
핵심 요점
메모:
암호
코드는 비교적 간단합니다. 예방 조치는 자신의 쿠키를 찾는 것입니다. yourcookie를 당신의 쿠키 끈으로 지정하고 직접 실행하십시오.
가장 중요한 것은 게시물이 존재하는지 여부를 결정하는 것입니다. 이것은 GET 요청이며 Post와 함께 회신을 보냅니다. 회신 메시지는 MapData.put ( "Message", "Friendly Help")에서 "친절한 도움"으로 하드 코딩되어 있습니다.
import java.io.bytearrayoutputStream; import java.io.ioexception; import java.io.inputStream; import java.io.outputStream; import java.io.unsupportedencodingException; import java.net.httpurlconnection; import java.net.malformedurectle; java.net.urlencoder; import java.util.linkedhashmap; import java.util.map; public class inter {private static final string baserefer = "http://rs.xidian.edu.cn/forum.php?mod=viewthread&tid="; 개인 정적 최종 문자열 YourCookie = "Q8QA_2132_SALTKEY = G1NJJJ3O; Q8QA_2132_LASTVESIT = 1438243699; Q8QA_2132_LASTCHECKFEED = 256730%7C1438252008; q8qa_2132_auth = e11aehxplgtypffffdk72yjzegjhl1v70cuxxdtj71vbu2dyuh%2bqhw3pgojhsfxfjbgvgvgg1v%2bqld0lt8kg6j%2b40w0; Q8QA_2132_ST_T = 256730%7C1438571068%7C51F8A322985E44F65FF1143329E6779A; Q8QA_2132_ULASTACTIVITIVE = D7DEGFMAWG5AGHSHMT%2BWCQ1L91ZNQPEA57P%2F0VT7VHDC8DROUGTT; Q8QA_2132_VISITEDFID = 72D551D215D113D13D142D22D217D548; Q8QA_2132_VIEWID = TID_773850; public static void main (String [] args) {int startId = 774210; // (int i = 0; i <100; i ++) {postMessage (startId); startId ++; }} public static boolean isexist (int id) {문자열 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 ( "사용자 에이전트", "Mozilla/5.0 (Windows NT 6.1) AppleWebkit/537.36 (Gecko Like Gecko) Chrome/38.0.2125.104 Safari/537.36"); con.addrequestProperty ( "참조", "http://t.dianping.com/register"); con.setRequestMethod ( "get"); if (con.getResponseCode () == 200) {inputStream inputstr = con.getInputStream (); 문자열 정보 = 새 문자열 (streamTool.Read (inputStr), "UTF-8"); if (info.contains ( "죄송합니다, 지정된 주제가 존재하지 않거나 삭제되었거나 검토 중이거나 검토 중입니다")) {System.out.println ( "id =" + id + "게시물이 존재하거나 삭제되었습니다!"); 거짓을 반환합니다. }}} catch (marformedurlexception e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (ioexception e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (예외 e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } true를 반환합니다. } public static void postMessage (int id) {if (! isexist (id)) {return; } 문자열 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 ( "인쇄", "예"); mapdata.put ( "handlekey", "fastpost"); mapdata.put ( "Inajax", "1"); mapData.put ( "메시지", "우정 지원"); mapData.put ( "Formhash", "86ec5d81"); {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 ( "내용 길이", String.valueof (path.length ())); Con.SetRequestProperty ( "사용자 에이전트", "Mozilla/5.0 (Windows NT 6.1) AppleWebkit/537.36 (Gecko와 같은 KHTML) Chrome/38.0.2125.104 Safari/537.36"); Con.setRequestProperty ( "쿠키", YourCookie); con.setdooutput (true); outputStream outstr = con.getOutputStream (); outstr.write (path.toString (). getBytes ()); if (con.getResponseCode () == 200) {inputStream inputstr = con.getInputStream (); 문자열 정보 = 새 문자열 (streamTool.Read (inputStr), "UTF-8"); System.out.println ( "in id =" + id + "성공적으로 게시되었습니다!"); try {thread.sleep (20 * 1000); } catch (InterruptedException e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); }}} catch (UnsupportedEncodingException e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (marlomedurlexception e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (ioexception e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (예외 e) {// todo 자동 생성 캐치 블록 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 (); Outstr.tobytearRay ()를 반환합니다. }}복제 다이어그램
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되고 게시물에 대한 자동 답장을 가능하게하기를 바랍니다.