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 class Test{
public static void main(String[] args) throws ClientProtocolException,IOException{
String loginurl= "http://www.renren.com/PLogin.do" ;
String username= "*****@qq.com" ;
String password= "*****" ;
System.out.println(Test.posturl(loginurl,username,password));
}
public static String posturl(String loginurl,String username,String
password) throws ClientProtocolException, IOException{
HttpClient httpclient1 = new DefaultHttpClient();
HttpPost httppost = new HttpPost(loginurl);
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
formparams.add( new BasicNameValuePair( "email" ,username));
formparams.add( new BasicNameValuePair( "password" ,password));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(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 = new HttpGet(login_success);
httpclient2 = new DefaultHttpClient();
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 ...
随机推荐
- javascript 中的数据驱动页面模式
前段时间一直在想前端MVC的意义.这个话题仁者见仁,但是MVC的使用方法给我提了一个管理数据的有意思的想法--数据管理和数据驱动页面.我们以前的思路一直是事件驱动页面,事件驱动页面合乎逻辑而且节约代码 ...
- 将[{},{}]转为dict
经常遇到一种需求,需要把从数据库取出的数据,转为dict对象([{}, {},...]-->dict). rs = [{, , "name":"edf"} ...
- 如何在Webstorm中添加js库 (青瓷H5游戏引擎)
js等动态语言编码最大的缺点就是没有智能补全代码,webstorm做到了. qici_engine作为开发使用的库,如果能智能解析成提示再好不过了,经测试80%左右都有提示,已经很好了. 其他js库同 ...
- android按行读取文件内容的几个方法
一.简单版 import java.io.FileInputStream; void readFileOnLine(){ String strFileName = "Filename.txt ...
- PHPExcel导出excel
如果导出中文时出现乱码,可以尝试将字符串转换成gb2312,例如下面就把$yourStr从utf-8转换成了gb2312: $yourStr = mb_convert_encoding("g ...
- 从用python自动生成.h的头文件集合和类声明集合到用python读写文件
最近在用python自动生成c++的类.因为这些类会根据需求不同产生不同的类,所以需要用python自动生成.由于会产生大量的类,而且这些类是变化的.所以如果是在某个.h中要用include来加载这些 ...
- Codeforces Round #Pi (Div. 2)
上次比完赛就准备写了, 结果懒癌发作了, 拖到了现在. Problem_A: 题意: 在一条x轴上有n座城市, 每个城市之间的距离就是它们对应坐标的距离, 现在求出每个城市到其他城市的最近距离和最远距 ...
- iOS 宏定义_16进制色值转化为RGB返回UIColor类型对象
// 十六进制颜色 #define COLOR_WITH_HEX(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) ...
- socket、tcp、http
第一部分.概念的理解 1.什么是Socket? Socket又称之为“套接字”,是系统提供的用于网络通信的方法.它的实质并不是一种协议,没有规定计算机应当怎么样传递消息,只是给程序员提供了一个发送消息 ...
- iOS便捷开发工具分享
项目/代码优化工具 1.objec_dep,可以了解项目中各个类的关联信息,了解项目中无效文件,知道双向应用的文件. 下载地址: https://github.com/nst/objc_dep 2.b ...