参考网址:
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
 
Java code
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;

}
}

  1. publicclass RenRen {
  2. // The configuration items
  3. privatestatic String userName ="YourMailinRenren";
  4. privatestatic String password ="YourPassword";
  5. privatestatic String redirectURL ="http://blog.renren.com/blog/304317577/449470467";
  6. // Don't change the following URL
  7. privatestatic String renRenLoginURL ="http://www.renren.com/PLogin.do";
  8. // The HttpClient is used in one session
  9. private HttpResponse response;
  10. private DefaultHttpClient httpclient =new DefaultHttpClient();
  11. privateboolean login() {
  12. HttpPost httpost = new HttpPost(renRenLoginURL);
  13. // All the parameters post to the web site
  14. List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  15. nvps.add(new BasicNameValuePair("origURL", redirectURL));
  16. nvps.add(new BasicNameValuePair("domain","renren.com"));
  17. nvps.add(new BasicNameValuePair("isplogin","true"));
  18. nvps.add(new BasicNameValuePair("formName",""));
  19. nvps.add(new BasicNameValuePair("method",""));
  20. nvps.add(new BasicNameValuePair("submit","登录"));
  21. nvps.add(new BasicNameValuePair("email", userName));
  22. nvps.add(new BasicNameValuePair("password", password));
  23. try {
  24. httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
  25. response = httpclient.execute(httpost);
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. returnfalse;
  29. } finally {
  30. httpost.abort();
  31. }
  32. returntrue;
  33. }
  34. private String getRedirectLocation() {
  35. Header locationHeader = response.getFirstHeader("Location");
  36. if (locationHeader == null) {
  37. returnnull;
  38. }
  39. return locationHeader.getValue();
  40. }
  41. private String getText(String redirectLocation) {
  42. HttpGet httpget = new HttpGet(redirectLocation);
  43. // Create a response handler
  44. ResponseHandler<String> responseHandler = new BasicResponseHandler();
  45. String responseBody = "";
  46. try {
  47. responseBody = httpclient.execute(httpget, responseHandler);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. responseBody = null;
  51. } finally {
  52. httpget.abort();
  53. httpclient.getConnectionManager().shutdown();
  54. }
  55. return responseBody;
  56. }
  57. publicvoid printText() {
  58. if (login()) {
  59. String redirectLocation = getRedirectLocation();
  60. if (redirectLocation != null) {
  61. System.out.println(getText(redirectLocation));
  62. }
  63. }
  64. }
  65. publicstaticvoid main(String[] args) {
  66. RenRen renRen = new RenRen();
  67. renRen.printText();
  68. }
  69. }
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();
}
}
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。

HTTPClient实现java自动登录人人网的更多相关文章

  1. java 自动登录代码

    javaBean的代码    package bean;    import java.io.Serializable;    public class Admin implements Serial ...

  2. Java 扫描微信公众号二维码,关注并自动登录网站

    https://blog.csdn.net/qq_42851002/article/details/81327770 场景:用户扫描微信公众号的二维码,关注后自动登录网站,若已关注则直接登录. 逻辑: ...

  3. Java通过httpclient获取cookie模拟登录

    package Step1; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Htt ...

  4. java代码实现自动登录功能

    通常我们登录某网站,会有选择保存几天,或者是几个星期不用登录,之后输入该网站地址无需登录直接进入主页面,那么这就叫做自动登录,怎么实现呢,下面我以一个小例子来演示一下 登录页面:login.jsp & ...

  5. 单点登录 SSO, 自动登录 , java 加密,ssl原理, Tomcat配置SSL

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 单点登录的英文简称为SSO(single sign on),单点登录功能使得用户只要登录 ...

  6. java浏览器控件jxbrowser(简单demo模拟自动登录与点击)

    写在前面: 老大让我写个脚本自动给他写dms有一段时间了,说实话当时不知道老大指的这个脚本是什么?毕竟是做web的,难道是写个数据库sql语句脚本吗?也就放在了一边.巧了,最近一个朋友说他之前写了个程 ...

  7. [原创]java WEB学习笔记29:Cookie Demo 之自动登录

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  8. 爬虫模拟cookie自动登录(人人网自动登录)

    什么是cookie? 在网站中,HTTP请求时无状态的,也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是谁,cookie的出现就是为了解决这个问题,第一次登陆后服 ...

  9. 转:实现Java Web程序的自动登录

    有很多Web程序中第一次登录后,在一定时间内(如2个小时)再次访问同一个Web程序时就无需再次登录,而是直接进入程序的主界面(仅限于本机).实现这个功能关键就是服务端要识别客户的身份.而用Cookie ...

随机推荐

  1. MYSQL 错误 :Out of resources when opening file './datagather/mx_domain#P#p178.MYD' (Errcode: 24) 解决办法

    出现Out of resources when opening file './xxx.MYD' (Errcode: 24)错误是因为打开的文件数超过了my.cnf的--open-files-limi ...

  2. Win7下通过easyBCD引导安装Ubuntu14.04

    Ubuntu14.04作为目前最新版本的ubuntu系统,相信很多人都想在自己的电脑上安装一下,然而系统的安装方法各式各样,u盘法.grub引导法等等,这里我将介绍在win7系统下用easyBCD软件 ...

  3. about Red_Hat_Enterprise_Linux_7

    systemd systemd 是 Linux 的系统和服务管理程序,替换了 Red Hat Enterprise Linux 之前的发行本中使用的 SysV.systemd 与 SysV 和 Lin ...

  4. Linux下glui 的安装,以及错误解决

    下载源文件: http://sourceforge.net/projects/glui/ 2. 解压源文件 3. 用terminal进入glui-2.36/src文件 4. make 5. make之 ...

  5. Ubuntu 误改/etc/sudoers 文件权限

    添加用户时不小心修改了/etc/sudoers 权限,结果不能sudo了,Ubuntu默认关闭root帐户,结果傻X了,无法改回了. 方法如下: 1.重启机器,开机按ESC,进入恢复模式 2.此时,磁 ...

  6. Django如何设置proxy

    设置porxy的原因 一般情况下我们代理设置是针对与浏览器而言,通常只需在浏览器设置中进行配置,但它只针对浏览器有效,对我们自己编写的程序并任何效果,这时就需要我们在软件编码中加入代理设置. --- ...

  7. "git add -A" is equivalent to "git add .; git add -u".

    git add -A stages All git add . stages new and modified, without deleted git add -u stages modified ...

  8. C# Json反序列化处理

    最近换工作了 从客户端转到Web端 第一个任务就是去别人的页面上抓取数据 用到的是JSON 因为他们网站json的格式有点怪 所以 就在JSON反序列化上面 花了一点时间 首先用到的工具是http:/ ...

  9. dubbo 负载均衡中策略决策

    在dubbo中的服务端负载均衡配置,如果像以下情况,将需要决策最终的负载策略问题: <dubbo:application name="hello-world-server" ...

  10. Colletion View 简单的备忘

    UIColletionView 这篇只是做UIColletionView的常用属性.代理方法和数据源方法的备忘,之后做一些自定义布局,增加删除动画等. UIColletionViewFlowLayou ...