阅读更多
import java.util.*;
import org.apache.commons.logging.Log;
import org.apache.http.*;
import org.apache.http.client.ResponseHandler;
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.*;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import java.util.TimerTask;
public class RenRen extends TimerTask{
// The configuration items
private static Logger logger = Logger.getLogger(RenRen.class);
private static int i=0;
private static String userName = "YourMailinRenren";
private static String password = "YourPassword";
private static String redirectURL = "http://10.140.105.75:8888/c/portal/layout?p_l_id=PUB.1.1";
// Don't change the following URL
private static String renRenLoginURL = "http://10.140.105.77:8888/ND18671/servlet/com.sdjxd.pms.platform.serviceBreak.Invoke";
//private static String renRenLoginURL = "http://10.140.105.75/c/portal/layout?p_l_id=PUB.1.1";
// 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 nvps = new ArrayList();
//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("_c", "com.jxd.comm.plat.LoginNum"));
nvps.add(new BasicNameValuePair("_m", "log"));
nvps.add(new BasicNameValuePair("_p0", "\"xiekefeng\""));
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
httpost.abort();
}
return true;
}
private boolean login3() {
KaiXinJS kx=new KaiXinJS();
;
HttpPost httpost = new HttpPost(renRenLoginURL);
// All the parameters post to the web site
List nvps = new ArrayList();
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("_c", "com.sdjxd.pms.platform.organize.User"));
nvps.add(new BasicNameValuePair("_m", "loginByEncode"));
//nvps.add(new BasicNameValuePair("_p0", "%22c29uZ2hhaWJpbg%3D%3D%22"));
nvps.add(new BasicNameValuePair("_p0", "\""+kx.getPassword("xiekefeng")+"\""));
nvps.add(new BasicNameValuePair("_p1", "\"21218CCA77804D2BA1922C33E0151105\""));
try {
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
response = httpclient.execute(httpost);
System.out.println(response);
} 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) {
HttpPost httpPost=new HttpPost(redirectLocation);
//HttpGet httpget = new HttpGet(redirectLocation);
// Create a response handler
ResponseHandler responseHandler = new BasicResponseHandler();
String responseBody = "";
try {
//responseBody = httpclient.execute(httpget, responseHandler);
responseBody = httpclient.execute(httpPost, responseHandler);
} catch (Exception e) {
e.printStackTrace();
responseBody = null;
} finally {
//httpget.abort();
// httpPost.abort();
//httpclient.getConnectionManager().shutdown();
}
return responseBody;
}
public void printText() {
if (login()) {
String redirectLocation = getRedirectLocation();
redirectLocation="http://10.140.105.75/c/portal/layout?p_l_id=PUB.1.1";
System.out.println(redirectLocation);
if (redirectLocation != null) {
// System.out.println(getText(redirectLocation));
}
}
}
public void printText2(){
login3();
login();
}
public void postDirect(){
//login3();
getText("http://10.140.105.77:8888/ND18671/servlet/com.sdjxd.pms.platform.serviceBreak.Invoke?_c=com.sdjxd.pms.platform.organize.User&_m=loginByEncode&_p0=%22c29uZ2hhaWJpbg%3D%3D%22&_p1=%2221218CCA77804D2BA1922C33E0151105%22");
getText("http://10.140.105.77:8888/ND18671/servlet/com.sdjxd.pms.platform.serviceBreak.Invoke?_c=com.jxd.comm.plat.LoginNum&_m=log&_p0=%22songhaibin%22");
//slogin();
System.out.println("xing");
httpclient.getConnectionManager().shutdown();
}
public void run(){
RenRen renRen = new RenRen();
renRen.printText2();
i++;
if(i==5){
//System.out.println("zhongzhi");
logger.info("jiesu");
System.exit(0);
}
//System.out.println("chengxingfang");
logger.info("chengxingfang.");
}
/*
public static void main(String[] args) {
RenRen renRen = new RenRen();
renRen.printText2();
//renRen.postDirect();
System.out.println("chengxingfang");
}*/
}