HttpComponents实战
来源:互联网 发布:同账号 苹果 软件 编辑:程序博客网 时间:2024/05/16 19:13
注册某论坛,对新人限制非常多,处处不便。
看到可以通过邀请注册快速活动经验,动起主意,想通过程序快速注册多个帐号来获取经验。
试验发现,单ip720小时内只能注册一个帐号,虽说可以不断重启路由来重新获得ip但还嫌麻烦。
想到平常用的 GAE 翻墙,google的代理服务器肯定很多,一定有很多不同的ip。
开始尝试 httpcomponents通过GAE代理连接 ip138,获取到美国ip则说明代理成功。
1.本地 GAE代理服务开好(具体方法搜“GAE翻@墙”)
2.代码
- package com.zhh.examples.client;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpHost;
- import org.apache.http.HttpResponse;
- import org.apache.http.auth.AuthScope;
- import org.apache.http.auth.UsernamePasswordCredentials;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.conn.params.ConnRoutePNames;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.util.EntityUtils;
- public class ProxyDemo {
- public static void main(String[] args) throws Exception {
- String proxyUrl = "127.0.0.1";
- int proxyPort = 8087;
- String url = "http://iframe.ip138.com/city.asp";
- DefaultHttpClient client = new DefaultHttpClient();
- client.getCredentialsProvider().setCredentials(
- new AuthScope(proxyUrl, proxyPort),
- new UsernamePasswordCredentials("", ""));
- HttpHost proxy = new HttpHost(proxyUrl, proxyPort);
- client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
- // 设置代理结束
- HttpPost post = new HttpPost(url);
- HttpResponse response = client.execute(post);
- // 打印出状态码
- System.out.println(response.getStatusLine());
- HttpEntity entity = response.getEntity();
- if (null != entity){
- System.out.println("Response content length: " + entity.getContentLength());
- System.out.println("Response content:\n" + EntityUtils.toString(entity));
- }
- }
- }
发现返回的网页内容 显示美国ip,代理成功。再接再厉。
尝试通过代理注册帐号
- package com.zhh.examples.client;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.http.Consts;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpHost;
- import org.apache.http.HttpResponse;
- import org.apache.http.NameValuePair;
- import org.apache.http.auth.AuthScope;
- import org.apache.http.auth.UsernamePasswordCredentials;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.conn.params.ConnRoutePNames;
- import org.apache.http.cookie.Cookie;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.util.EntityUtils;
- public class RegDG {
- public static void main(String[] args) throws Exception {
- String proxyUrl = "127.0.0.1";
- int proxyPort = 8087;
- String url = "http://www.baidu.com/?a=btpcgo";//baidu为虚拟
- DefaultHttpClient client = new DefaultHttpClient(new ThreadSafeClientConnManager());
- //设置代理
- client.getCredentialsProvider().setCredentials(
- new AuthScope(proxyUrl, proxyPort),
- new UsernamePasswordCredentials("", ""));
- HttpHost proxy = new HttpHost(proxyUrl, proxyPort);
- client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
- //请求url 使a=btpcgo存入cookie 注册时服务端会检测是哪个用户邀请
- HttpGet get = new HttpGet(url);
- HttpResponse response = client.execute(get);
- System.out.println(response.getStatusLine());
- HttpEntity entity = response.getEntity();
- if (null != entity){
- System.out.println("Response content length: " + entity.getContentLength());
- // System.out.println("Response content:\n" + EntityUtils.toString(entity));
- }
- //查看cookies值
- List<Cookie> cookies = client.getCookieStore().getCookies();
- if (null != cookies){
- for (Cookie cookie:cookies){
- System.out.println(cookie.getName()+" - " + cookie.getValue());
- }
- }
- //注册
- String regUrl = "http://www.baidu.com/register.php";
- String regName = "test" + (int)(Math.random()*100000);
- String regPwd = "12345679";
- String regEmail = regName + "@163.com";
- System.out.println("=============Register===============" + regName);
- HttpPost regPost = new HttpPost(regUrl);
- List<NameValuePair> nvps = new ArrayList<NameValuePair>();
- nvps.add(new BasicNameValuePair("forward", ""));
- nvps.add(new BasicNameValuePair("step", "2"));
- nvps.add(new BasicNameValuePair("_hexie", "a3fb2f2b"));
- nvps.add(new BasicNameValuePair("regname", regName));
- nvps.add(new BasicNameValuePair("regpwd", regPwd));
- nvps.add(new BasicNameValuePair("regpwdrepeat", regPwd));
- nvps.add(new BasicNameValuePair("regemail", regEmail));
- nvps.add(new BasicNameValuePair("rgpermit", "1"));
- regPost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8));
- HttpResponse response_reg = client.execute(regPost);
- HttpEntity regEntity = response_reg.getEntity();
- System.out.println(response_reg.getStatusLine());
- if (null != regEntity) {
- String content = new String(EntityUtils.toString(regEntity).getBytes("iso-8859-1"), "gbk");
- System.out.println("Response content:\n" + content);
- }
- client.getConnectionManager().shutdown();
- }
- }
如果有大量代理服务器,可以依次替换不同代理服务器注册,效率更高。
对于注册有验证码的,可以使用 "Tesseract-ocr" 或 “tesseract” 来自动识别验证码,对一般验证码还是相当有把握的。
0 0
- HttpComponents实战
- HttpComponents实战
- HttpComponents实战
- HttpComponents
- httpcomponents练习
- HttpComponents概述
- Apache HttpComponents
- Apache HttpComponents
- HttpComponents入门解析
- HttpComponents入门解析
- HttpComponents入门解析
- HttpComponents入门解析
- Apache HttpComponents是什么
- HttpComponents入门解析
- HttpComponents入门解析
- Apache HttpComponents 简单说明
- HttpComponents入门解析
- 踩坑记:httpComponents 的 EntityUtils
- 在ASP.NET MVC中通过URL路由实现对多语言的支持
- ***********ListView的使用***********
- Swift based iBeacon App Development with CoreLocation on Apple iOS 7/8
- 互联网+时代,是更加开放还是封闭
- jquery1.8 获取option的对象进行操作
- HttpComponents实战
- Angular关于$watch,$apply 以及 $digest的工作原理及相关知识点
- MySQL 集群方案相关问题
- 利用sqoop将hive数据导入导出数据到mysql
- Linux下的iwpriv(iwlist、iwconfig)的简单应用
- ViewPager预加载问题和onCreateView多次调用问题的解决
- ROS进阶学习手记 7 -- RViz仿真实例1
- 可爱的Jython
- 帧动画