HTTPClient实现java自动登录人人网
https://passport.csdn.net/account/login
http://www.iteye.com/topic/638206
httpClient
http://bbs.csdn.net/topics/390495789
http://developer.51cto.com/art/200806/76048.htm
http://my.oschina.net/lldy/blog/57086
http://blog.csdn.net/yodlove/article/details/5938022
http://java.chinaitlab.com/net/870192.html
http://blog.csdn.net/wguoyong/article/details/6883706
http://www.holdjava.com/networkprogramme/213519.htm
http://www.th7.cn/Program/java/2011/08/26/40877.shtml
http://www.oschina.net/question/96568_91032
http://blog.csdn.net/passportandy/article/details/7101913
http://www.cr173.com/soft/61128.html
http://wenku.baidu.com/link?url=d4RXqVqu05FmVVc23zuL0bA8Q9CXIaOOeBu7lYm9mlEaUwFp3X9EGfxOldUqO9pQtIh6Cf37IclGbTURFPnZRBGkn-tjYI3_vFUO2J5PVn7
http://www.oschina.net/question/1378722_130120
http://csstome.iteye.com/blog/936276
http://extjs2.iteye.com/blog/807039
http://www.docin.com/p-611908008.html
http://blog.163.com/ww20042005@126/blog/static/949490452010101102817765/
http://www.pudn.com/downloads322/sourcecode/java/jsp/detail1422233.html
http://www.oschina.net/question/944872_111722
http://bbs.csdn.net/topics/390651559?page=1#post-396177585
http://www.52pojie.cn/thread-56913-1-1.html
http://www.yc-edu.org/javapeixun/2129.html
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
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.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
//import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
public classTest{
publicstaticvoidmain(String[] args)throwsClientProtocolException,IOException{
String loginurl="http://www.renren.com/PLogin.do";
String username="*****@qq.com";
String password="*****";
System.out.println(Test.posturl(loginurl,username,password));
}
publicstaticString posturl(String loginurl,String username,String
password)throwsClientProtocolException, IOException{
HttpClient httpclient1 =newDefaultHttpClient();
HttpPost httppost =newHttpPost(loginurl);
List<NameValuePair> formparams =newArrayList<NameValuePair>();
formparams.add(newBasicNameValuePair("email",username));
formparams.add(newBasicNameValuePair("password",password));
UrlEncodedFormEntity entity =newUrlEncodedFormEntity(formparams,"utf-8");
httppost.setEntity(entity);
String str="";
HttpClient httpclient2=null;
try{
HttpResponse response1 = httpclient1.execute(httppost);
String login_success=response1.getFirstHeader("Location").getValue();//获取登陆成功之后跳转链接
System.out.println(login_success);
HttpGet httpget =newHttpGet(login_success);
httpclient2 =newDefaultHttpClient();
HttpResponse response2=httpclient2.execute(httpget);
str=EntityUtils.toString(response2.getEntity());
httppost.abort();
httpget.abort();
}finally{
httpclient1.getConnectionManager().shutdown();
httpclient2.getConnectionManager().shutdown();
}
return str;
}
}
|
- publicclass RenRen {
- // The configuration items
- privatestatic String userName ="YourMailinRenren";
- privatestatic String password ="YourPassword";
- privatestatic String redirectURL ="http://blog.renren.com/blog/304317577/449470467";
- // Don't change the following URL
- privatestatic String renRenLoginURL ="http://www.renren.com/PLogin.do";
- // The HttpClient is used in one session
- private HttpResponse response;
- private DefaultHttpClient httpclient =new DefaultHttpClient();
- privateboolean login() {
- HttpPost httpost = new HttpPost(renRenLoginURL);
- // All the parameters post to the web site
- List<NameValuePair> nvps = new ArrayList<NameValuePair>();
- nvps.add(new BasicNameValuePair("origURL", redirectURL));
- nvps.add(new BasicNameValuePair("domain","renren.com"));
- nvps.add(new BasicNameValuePair("isplogin","true"));
- nvps.add(new BasicNameValuePair("formName",""));
- nvps.add(new BasicNameValuePair("method",""));
- nvps.add(new BasicNameValuePair("submit","登录"));
- nvps.add(new BasicNameValuePair("email", userName));
- nvps.add(new BasicNameValuePair("password", password));
- try {
- httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
- response = httpclient.execute(httpost);
- } catch (Exception e) {
- e.printStackTrace();
- returnfalse;
- } finally {
- httpost.abort();
- }
- returntrue;
- }
- private String getRedirectLocation() {
- Header locationHeader = response.getFirstHeader("Location");
- if (locationHeader == null) {
- returnnull;
- }
- return locationHeader.getValue();
- }
- private String getText(String redirectLocation) {
- HttpGet httpget = new HttpGet(redirectLocation);
- // Create a response handler
- ResponseHandler<String> responseHandler = new BasicResponseHandler();
- String responseBody = "";
- try {
- responseBody = httpclient.execute(httpget, responseHandler);
- } catch (Exception e) {
- e.printStackTrace();
- responseBody = null;
- } finally {
- httpget.abort();
- httpclient.getConnectionManager().shutdown();
- }
- return responseBody;
- }
- publicvoid printText() {
- if (login()) {
- String redirectLocation = getRedirectLocation();
- if (redirectLocation != null) {
- System.out.println(getText(redirectLocation));
- }
- }
- }
- publicstaticvoid main(String[] args) {
- RenRen renRen = new RenRen();
- renRen.printText();
- }
- }
public class RenRen {
// The configuration items
private static String userName = "YourMailinRenren";
private static String password = "YourPassword";
private static String redirectURL = "http://blog.renren.com/blog/304317577/449470467";
// Don't change the following URL
private static String renRenLoginURL = "http://www.renren.com/PLogin.do";
// The HttpClient is used in one session
private HttpResponse response;
private DefaultHttpClient httpclient = new DefaultHttpClient();
private boolean login() {
HttpPost httpost = new HttpPost(renRenLoginURL);
// All the parameters post to the web site
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("origURL", redirectURL));
nvps.add(new BasicNameValuePair("domain", "renren.com"));
nvps.add(new BasicNameValuePair("isplogin", "true"));
nvps.add(new BasicNameValuePair("formName", ""));
nvps.add(new BasicNameValuePair("method", ""));
nvps.add(new BasicNameValuePair("submit", "登录"));
nvps.add(new BasicNameValuePair("email", userName));
nvps.add(new BasicNameValuePair("password", password));
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
httpost.abort();
}
return true;
}
private String getRedirectLocation() {
Header locationHeader = response.getFirstHeader("Location");
if (locationHeader == null) {
return null;
}
return locationHeader.getValue();
}
private String getText(String redirectLocation) {
HttpGet httpget = new HttpGet(redirectLocation);
// Create a response handler
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = "";
try {
responseBody = httpclient.execute(httpget, responseHandler);
} catch (Exception e) {
e.printStackTrace();
responseBody = null;
} finally {
httpget.abort();
httpclient.getConnectionManager().shutdown();
}
return responseBody;
}
public void printText() {
if (login()) {
String redirectLocation = getRedirectLocation();
if (redirectLocation != null) {
System.out.println(getText(redirectLocation));
}
}
}
public static void main(String[] args) {
RenRen renRen = new RenRen();
renRen.printText();
}
}
HTTPClient实现java自动登录人人网的更多相关文章
- java 自动登录代码
javaBean的代码 package bean; import java.io.Serializable; public class Admin implements Serial ...
- Java 扫描微信公众号二维码,关注并自动登录网站
https://blog.csdn.net/qq_42851002/article/details/81327770 场景:用户扫描微信公众号的二维码,关注后自动登录网站,若已关注则直接登录. 逻辑: ...
- Java通过httpclient获取cookie模拟登录
package Step1; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Htt ...
- java代码实现自动登录功能
通常我们登录某网站,会有选择保存几天,或者是几个星期不用登录,之后输入该网站地址无需登录直接进入主页面,那么这就叫做自动登录,怎么实现呢,下面我以一个小例子来演示一下 登录页面:login.jsp & ...
- 单点登录 SSO, 自动登录 , java 加密,ssl原理, Tomcat配置SSL
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 单点登录的英文简称为SSO(single sign on),单点登录功能使得用户只要登录 ...
- java浏览器控件jxbrowser(简单demo模拟自动登录与点击)
写在前面: 老大让我写个脚本自动给他写dms有一段时间了,说实话当时不知道老大指的这个脚本是什么?毕竟是做web的,难道是写个数据库sql语句脚本吗?也就放在了一边.巧了,最近一个朋友说他之前写了个程 ...
- [原创]java WEB学习笔记29:Cookie Demo 之自动登录
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- 爬虫模拟cookie自动登录(人人网自动登录)
什么是cookie? 在网站中,HTTP请求时无状态的,也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是谁,cookie的出现就是为了解决这个问题,第一次登陆后服 ...
- 转:实现Java Web程序的自动登录
有很多Web程序中第一次登录后,在一定时间内(如2个小时)再次访问同一个Web程序时就无需再次登录,而是直接进入程序的主界面(仅限于本机).实现这个功能关键就是服务端要识别客户的身份.而用Cookie ...
随机推荐
- Qt5下的常见问题————C1083
很多像我一样刚开始学习Qt的时候都会遇到这样的问题.例如"fatal error C1083: 无法打开包括文件:“QApplication”: No such file or direct ...
- yii下多条件多表组合查询以及自写ajax分页
多条件组合查询主要用到yii的CDbCriteria,这个类很多oem框架都有,非常好用. 前台表单 前台查询表单效果是这样的,多个条件组,每个组里放多个input,name为数组.当任何一个复选框被 ...
- __set($key,$values) 和__get($varName) 魔术方法设置读取私有属性
__set($key,$val) 对类内私有属性赋值 作用:对私有属性的处理 当在类外对类内的私有属性赋值时会自动调用此函数 __get($varName) 读取类内私有属性 作用:虽然可以外部访问, ...
- 编程思想—面向切面编程(AOP)
谈到面向切面的编程,我们很容易关联到面向对象编程(OOP).个人对这两种编程方式的解释为:两种编程思想只是站在编程的角度问题. OOP注重的是对象,怎么对对象行为和方法的抽象.如何封装一个具有完整属性 ...
- Xcode中使用GitHub详解
为了熟悉git命令及将写的小Demo能够管理起来方便日后查询,所以选择使用GitHub. 现在我们来说说Xcode中如何使用GitHub--- 一.当然是要先有GitHub帐号并登录了(没有的注册一个 ...
- hadoop的一些重要配置参数
hadoop集群管理内存设置 Mapreduce内存使用设置 hadoop job重要性能参数
- python获取本地ip地址的方法
#_*_coding:utf8_*_ #以下两种方法可以在ubuntu下或者windows下获得本地的IP地址 import socket # 方法一 localIP = socket.gethost ...
- 当一个控件属性不存在的时候,IDE会出错在这里
procedure TWinControl.ReadState(Reader: TReader); begin DisableAlign; try inherited ReadState(Reader ...
- <转>SFTP 和FTPS的区别是什么?
SFTP 和FTPS都是为ftp连接加密,协议非常相似. 一个是借助ssl协议加密,一个时借助ssh加密. ssl是为http/smtp等加密设计的,ssh是为telnet/ftp等加密.建立传输通道 ...
- 【HDOJ】1466 计算直线的交点数
找了个规律. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 21 ...