Recentemente, eu queria postar automaticamente e responde automaticamente. Eu tentei com um fórum e descobri que era viável, mas não foi usado novamente no futuro para evitar afetar a operação normal do fórum.
1. O formato do link post é
http: //bbs.***.***.**/Forum.php? Mod = ViewThread & Tid = 774210
A alteração do número no final do 774210 pode ser obtida com postagens diferentes
2. Evite que o post seja excluído novamente e determine se a postagem existe
3. Aumente o número de identificação depois e faça uma solicitação de postagem para responder a cada link
Pontos -chave
Responder requer informações de login de usuário, é usar cookies
Outra maneira é simular o login
Este artigo adota o primeiro
Determinar se a postagem correspondente da URL existe
É possível que o usuário tenha postado uma postagem, por exemplo, o URL é http: //bbs.***.***.**/Forum.php? Mod = ViewThread & Tid = 774200
Mais tarde, o usuário da postagem foi excluído ou excluído pelo administrador. Embora o post tenha desaparecido, o TID = 774200 ainda existe.
public static boolean isexist (int id) {string tmppath = baserefer + id; URL URL; tente {url = novo url (tmppath); HttpurlConnection con = (httpurlConnection) url.openconnection (); con.addrequestProperty ("conteúdo-tipo", "text/html; charset = utf-8"); Con.AddRequestProperty ("User-Agent", "Mozilla/5.0 (Windows NT 6.1) Applewebkit/537.36 (KHTML, como Gecko) Chrome/38.0.2125.104 Safari/537.36"); con.addrequestProperty ("referente", "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 ("Desculpe, o tópico especificado não existe ou foi excluído ou está sendo revisado")) {System.out.println ("id =" + id + "existe ou foi excluído!"); retornar falso; }}} catch (malformedUrlexception e) {// TODO GATE GENERADO AUTOGERATO E.PRINTSTACKTRACE (); } catch (ioexception e) {// TODO GATO GENERADO AUTOMENTADO BLOCO E.PRINTSTACKTRACE (); } Catch (Exceção e) {// TODO BLOCO DE CAPAGEM AUTOMENTADO E.PRINTSTACKTRACE (); } Catch (Exceção e) {// TODO BLOCO DE CAPAGEM AUTOMENTADO E.PRINTSTACKTRACE (); } Catch (Exceção e) {// TODO BLOCO DE CAPAGEM AUTOMENTADO E.PRINTSTACKTRACE (); } Catch (Exceção e) {// TODO BLOCO DE CAPAGEM AUTOMENTADO E.PRINTSTACKTRACE (); } retornar true;}Simular postagem <br /> O código é relativamente simples, a precaução é encontrar seu próprio cookie e atribuí -lo a string yourcookie
Envie uma resposta usando a postagem e a mensagem de resposta está no mapData.put ("mensagem", "Ajuda da amizade")
String final privada String Basefer = "http: //bbs.**.**.**/Forum.php? Mod = ViewThread & Tid ="; String final estática privada YOURCOOKIE = "Q8QA_2132_SALTKEY = **; Q8QA_2132_LASTVIST = **** 36; 774210; // você precisa mudar para (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); Mapa <string, string> mapData = new LinkedHashmap <string, string> (); mapData.put ("mod", "post"); mapData.put ("ação", "resposta"); mapData.put ("ResponderSubMit", "Sim"); mapData.put ("Infloat", "Sim"); mapData.put ("HandleKey", "FastPost"); mapData.put ("inajax", "1"); mapData.put ("mensagem", "suporte de amizade"); mapData.put ("formhash", "86ec5d81"); tente {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 ("Length-comprimento", String.ValueOf (Path.Length ())); Con.SetRequestProperty ("User-Agent", "Mozilla/5.0 (Windows NT 6.1) Applewebkit/537.36 (KHTML, como Gecko) Chrome/38.0.2125.104 Safari/537.36"); Con.SetRequestProperty ("Cookie", YourCookie); Con.SetdoOutput (true); OutputStream exttr = con.getOutputStream (); strstr.Write (path.toString (). getBytes ()); if (con.getResponsecode () == 200) {inputStream inputStr = con.getInputStream (); String info = new String (Streamtool.read (InputStr), "UTF-8"); System.out.println ("enviado com sucesso em id =" + id + "!"); tente {thread.sleep (20 * 1000); } catch (interruptedException e) {// TODO BLOCO DE CATCH AUTOGERATIDO E.PRINTSTACKTRACE (); }} Catch (UnsupportEdEncodingException e) {// TODO BLOCO DE CATAGEM AUTOMENTADO E.PRINTSTACKTRACE (); } catch (malformedurlexception e) {// TODO BLOCO DE CATAGEM AUTOGERATO E.PRINTSTACKTRACE (); } catch (ioexception e) {// TODO GATO GENERADO AUTOMENTADO BLOCO E.PRINTSTACKTRACE (); } Catch (Exceção e) {// TODO BLOCO DE CAPAGEM AUTOMENTADO E.PRINTSTACKTRACE (); }} Há também um método de ferramenta que converte fluxos de entrada em bytes
classe Streamtool {public static byte [] read (inputStream inputStr) lança Exceção {bytearrayOutputStream strott = new ByteArrayOutputStream (); // TODO Método Gerado de Auto-Generado Byte [] buffer = novo byte [1024]; int len = 0; while ((len = inputStr.read (buffer))! = -1) {ssttr.Write (buffer, 0, len); } inputStr.close (); return sstr.tobyteArray (); }}Imagem de reprodução:
O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.