关于一个基于http的人们刷人气工具
关于一个基于http的人人刷人气工具
今天在网上发现了一个叫做Httpclient的包,可以模拟浏览器行为。所以我就打算用这个做一个人人刷人气的东西,顺便学习一下这个类库。有两种实现方法,一种是被动的去漫无目的的踩人家,期待别人来踩你。第二种是注册若干小号,然后用这些小号来踩自己。话不多说了,上代码~
在main函数里面用自己的小号去调用login函数就可以了。
希望能对大家有所帮助
今天在网上发现了一个叫做Httpclient的包,可以模拟浏览器行为。所以我就打算用这个做一个人人刷人气的东西,顺便学习一下这个类库。有两种实现方法,一种是被动的去漫无目的的踩人家,期待别人来踩你。第二种是注册若干小号,然后用这些小号来踩自己。话不多说了,上代码~
import java.io.IOException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.PostMethod; import Writer.writer; public class Check { public static void login(String email,String pwd){ HttpClient httpClient = new HttpClient(); //去掉cookie设置,采用httpclient的默认cookie设置 String url = "http://www.renren.com/PLogin.do"; String toget = "http://www.renren.com/profile.do?id=249689342"; PostMethod postMethod = new PostMethod(url); NameValuePair[] data = { new NameValuePair("email", email), new NameValuePair("password", pwd), new NameValuePair("url", "/home/") }; postMethod.setRequestBody(data); try { int statusCode = httpClient.executeMethod(postMethod); System.out.println("statusCode--"+statusCode); if (statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { Header locationHeader = postMethod.getResponseHeader("location"); postMethod.releaseConnection(); if (locationHeader != null){ String cookieUrl = locationHeader.getValue(); System.out.println("cookieUrl--"+cookieUrl); //String r_url="http://www.renren.com"+cookieUrl;//修改302后的url System.out.println("r_url--"+cookieUrl); GetMethod getMethod = new GetMethod(cookieUrl); //httpClient.getState().addCookies(cookies); int status=httpClient.executeMethod(getMethod); if (status==200) { System.out.println("登陸成功"); } //System.out.println("status---"+status); //System.out.println(getMethod.getResponseBodyAsString()); //writer.writeMethod1(new String(getMethod.getResponseBodyAsString())); getMethod.releaseConnection(); } } postMethod.releaseConnection(); } catch (Exception e) { // System.err.println(e.getMessage()); } GetMethod getMethod=new GetMethod(toget); try { httpClient.executeMethod(getMethod); System.out.println("訪問成功"); //byte[] responseBody = getMethod.getResponseBody(); //writer.writeMethod1(new String(responseBody)); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args){ } }
在main函数里面用自己的小号去调用login函数就可以了。
希望能对大家有所帮助