参考网址:
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=d4RXqVqu05FmVVc23zuL0bA8Q9CXIaOOeBu7lYm9mlEaUwFp3X9EGfxOldUqO9pQtIh6Cf37Ic*URFPnZRBGkn-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
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=d4RXqVqu05FmVVc23zuL0bA8Q9CXIaOOeBu7lYm9mlEaUwFp3X9EGfxOldUqO9pQtIh6Cf37Ic*URFPnZRBGkn-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;
}
}
|
- 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文章版权属于作者,受法律保护。没有作者书面许可不得转载。