复制代码代码如下::
Paket com.lkb.test;
Import Java.util.ArrayList;
import Java.util.hashMap;
Import Java.util.iterator;
importieren java.util.list;
import Java.util.map;
import org.apache.http.httpresponse;
import org.apache.http.client.responseHandler;
import org.apache.http.client.entity.urlencoded forderity;
import org.apache.http.client.methods.httpget;
import org.apache.http.client.methods.httppost;
import org.apache.http.impl.client.basicresponseHandler;
import org.apache.http.impl.client.defaushttpclient;
import org.apache.http.message.basicnamevaluepair;
import org.apache.http.message.buffenedheader;
import org.apache.http.protocol.http;
import com.util.constant;
öffentliche Klasse jd {
// die Konfigurationselemente
private statische String -Redirecturl = "http://order.jd.com/center/List.action";
private statische String loginurl = "http://passport.jd.com/uc/login";
// Ändern Sie die folgende URL nicht
private statische String renrenloginurl = "https://passsport.jd.com/uc/loginservice";
// Der httpclient wird in einer Sitzung verwendet
private httPesponse -Antwort;
private defaulthttpclient httpclient = new Defaulthttpclient ();
öffentliche Karte <String, String> getParams () {
Karte <String, String> map = new HashMap <String, String> ();
String str = getText (loginurl);
String strs1 [] = str.split ("name =/" 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> <Eingabetyp =/" Hidden/"name =/" ");
String strs4 [] = str3s [1] .Split ("/>");
String strs5 [] = strs4 [0] .trim (). Split ("/" ");
String key = strs5 [0];
String -Wert = strs5 [2];
map.put (Schlüssel, Wert);
Rückgabekarte;
}
private boolean login () {
Map map = getParams ();
Httppost httpost = new httppost (renrenloginurl);
// Alle Parameter posten auf die Website
Liste <BasicNamevaluePair> nvps = new ArrayList <BasicNamevaluePair> ();
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 (Schlüssel) .ToString ();
NVPS.Add (New BasicNamevaluePair (Schlüssel, Wert));
}
versuchen {
httpost.setEntity (neue urlencodedformentity ((list <? erweitert org.apache.http.namevaluepair>) nvps, http.utf_8));
response = httpclient.execute (httpost);
} catch (Ausnahme e) {
E. printstacktrace ();
false zurückgeben;
} Endlich {
httpost.abort ();
}
zurückkehren;
}
private Zeichenfolge getRedirectLocation () {
BufferedHeader locationHeader = (bufferedHeader) response.getFirStheader ("Ort");
if (locationHeader == null) {
null zurückkehren;
}
return locumader.getValue ();
}
private String GetText (String recirectLocation) {
Httpget httpget = new httpget (RedirectLocation);
ReaktionsHandler <string> reaktionshandler = new BasicResponseHandler ();
String responseBody = "";
versuchen {
Antwortbodus = httpclient.execute (httpget, reaktionsgemäß);
} catch (Ausnahme e) {
E. printstacktrace ();
Antwortbody = null;
} Endlich {
httpget.abort ();
//httpclient.getConnectionManager (). Shutdown ();
}
Return ResponseBody;
}
public void printText () {
if (login ()) {
System.out.println (getText (redirecturl));
String recirectLocation = getRedirectLocation ();
if (recirectLocation! = null) {
System.out.println (getText (RedirectLocation));
}
}
}
public static void main (String [] args) {
Jd renren = new JD ();
//renren.getparams ();
renren.printtext ();
}
}