复制代码代码如下:
pacote com.lkb.test;
importar java.util.arraylist;
importar java.util.hashmap;
importar java.util.iterator;
importar java.util.list;
importar java.util.map;
importar org.apache.http.httpResponse;
importar org.apache.http.client.ResponseHandler;
importar org.apache.http.client.entity.urlencodedFormentity;
importar org.apache.http.client.methods.httpget;
importar org.apache.http.client.methods.httppost;
importar org.apache.http.impl.client.BasicResponseHandler;
importar org.apache.http.impl.client.defaulthttpClient;
importar org.apache.http.message.basicnameValuepair;
importar org.apache.http.message.bufferedHeader;
importar org.apache.http.protocol.http;
importação com.util.constant;
classe pública JD {
// Os itens de configuração
String estática privada redirecturl = "http://order.jd.com/center/list.action";
String estática privada loginurl = "http://passport.jd.com/uc/login";
// Não altere o seguinte URL
String estática privada Renrenloginurl = "https://passport.jd.com/uc/loginservice";
// o httpclient é usado em uma sessão
Resposta privada de HTTPRESPONHA;
private defaulthttpClient httpClient = new DefaULTHTTPCLIENT ();
mapa público <string, string> getParams () {
Mapa <string, string> map = new hashmap <string, string> ();
String str = getText (loginurl);
String strs1 [] = str.split ("nome =/" uuid/"value =/" ");
String strs2 [] = strs1 [1] .split ("/"/> ");
String uuid = strs2 [0];
map.put ("uuid", uuid);
System.out.println (strs2 [0]);
String str3s [] = strs1 [1] .split ("<span class =/" clr/"> </span> <tipo de entrada =/" hidden/"name =/" ");
String strs4 [] = str3s [1] .split ("/>");
String strs5 [] = strs4 [0] .Trim (). Split ("/" ");
String key = strs5 [0];
String Value = Strs5 [2];
map.put (chave, valor);
mapa de retorno;
}
Login booleano privado () {
Mapa mapa = getParams ();
HttpPost httpost = new httppost (renrenloginurl);
// Todos os parâmetros postam no site
Lista <SquaricNameValuepair> nvps = new ArrayList <SicNameValuepair> ();
nvps.add (new BasicNameValuepair ("returnurl", redirecturl));
nvps.add (new BasicNameValuepair ("LoginName", constant.username));
nvps.add (new BasicNameValuepair ("nloginpwd", constant.password));
nvps.add (new BasicNameValuepair ("loginpwd", constant.password));
Iterator it = map.keyset (). Iterator ();
while (it.hasnext ()) {
String key = it.Next (). ToString ();
String value = map.get (key) .ToString ();
nvps.add (new BasicNameValuepair (chave, valor));
}
tentar {
httpost.SetEntity (New UrlencodedFormentity ((List <? Extends org.apache.http.namevaluepair>) nvps, http.utf_8));
resposta = httpclient.execute (httpost);
} catch (Exceção e) {
E.PrintStackTrace ();
retornar falso;
} finalmente {
httpost.abort ();
}
retornar true;
}
Private String GetRredirectLocation () {
BufferHeader LocationHeader = (BufferDeader) Response.getFirStheader ("Localização");
if (locationheader == null) {
retornar nulo;
}
retornar locationheader.getValue ();
}
Private String getText (String redirectLocation) {
Httpget httpget = new httpget (redirectLocation);
ResponseHandler <String> ResponseHandler = new BasicResponseHandler ();
String ResponseBody = "";
tentar {
ResponseBody = httpclient.execute (httpGet, ResponseHandler);
} catch (Exceção e) {
E.PrintStackTrace ();
ResponseBody = NULL;
} finalmente {
httpget.abort ();
//httpclient.getConnectionManager (). Shutdown ();
}
resposta de resposta;
}
public void printText () {
if (login ()) {
System.out.println (getText (redirecturl));
String redirectLocation = getredirectLocation ();
if (redirectLocation! = null) {
System.out.println (getText (redirectLocation));
}
}
}
public static void main (string [] args) {
JD Renren = novo JD ();
//renren.getparams ();
Renren.printText ();
}
}