HTTPClient实现java自动登录人人网
2013-12-03 10:55
405 查看
参考网址: 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
Java代码
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();
}
}
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
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
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(); } }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
相关文章推荐
- HTTPClient实现java自动登录人人网
- java web session+cookie实现用户自动登录
- JavaWeb_使用Cookie模拟实现自动登录
- java_web用户的自动登录模块的实现
- java操作cookie 实现两周内自动登录 加密安全性问题
- java读写cookie实现自动登录
- java_web用户的自动登录模块的实现
- 如何实现网页程序自动登录(java)?
- Java网站中的自动登录功能如何实现 Session Cookie
- java 实现QQ自动登录(带验证码)
- python实现自动登录人人网并采集信息的方法
- 如何实现网页程序自动登录(java)?
- 自动登录 java实现 网络编程
- JavaWeb之过滤器实现自动登录案例
- 如何实现网页自动登录?或Java模拟Post表单
- java中使用过滤器实现自动登录
- Java传入用户名和密码并自动提交表单实现登录到其他系统的实例代码
- python实现人人网的自动登录
- python实现自动登录人人网并访问最近来访者实例
- [Java开发] cookie、session及实现记住密码,自动登录思路