최근에 자동으로 게시하고 자동으로 답장을 원했습니다. 나는 포럼으로 그것을 시도했지만 실현 가능하다는 것을 알았지 만 앞으로 포럼의 정상적인 작동에 영향을 미치지 않기 위해 다시 사용되지 않았다.
1. 게시물 링크의 형식은 다음과 같습니다
http : //bbs.********/forum.php? mod = viewthread & tid = 774210
774210 말의 숫자 변경은 다른 게시물을 얻음으로써 얻을 수 있습니다.
2. 게시물이 다시 삭제되지 않도록하고 게시물이 존재하는지 확인하십시오.
3. 나중에 ID 번호를 증가시키고 각 링크에 회신하기 위해 게시물 요청을 작성하십시오.
핵심 요점
답장에 사용자 로그인 정보가 필요합니다. 쿠키를 사용하는 것입니다.
또 다른 방법은 로그인을 시뮬레이션하는 것입니다
이 기사는 전자를 채택합니다
해당 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 ( "사용자 에이전트", "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 (); } catch (예외 e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (예외 e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } catch (예외 e) {// todo 자동 생성 캐치 블록 e.printstacktrace (); } return true;}<br /> 게시 시뮬레이션 코드는 비교적 간단합니다. 예방 조치는 자신의 쿠키를 찾아서 string yourcookie에 할당하는 것입니다.
Post를 사용하여 회신을 보내면 회신 메시지는 MapData.put ( "Message", "Friendship Help")에 있습니다.
개인 정적 최종 문자열 baserefer = "http : //bbs.** .** .**/forum.php? mod = viewthread & tid ="; private static final string yourCookie = "Q8QA_2132_SALTKEY = **; Q8QA_2132_LASTVISIT = **** 3699; gublic void Main (args)."; 774210; // (int i = 0; i <100; i ++) {postMessage (startId); startId ++; }} 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 ( "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 ()를 반환합니다. }}생식 이미지 :
위는이 기사의 모든 내용입니다. 모든 사람의 학습에 도움이되기를 바랍니다. 모든 사람이 wulin.com을 더 지원하기를 바랍니다.