复制代码代码如下:
แพ็คเกจ com.lkb.test;
นำเข้า java.util.arraylist;
นำเข้า java.util.hashmap;
นำเข้า java.util.iterator;
นำเข้า java.util.list;
นำเข้า java.util.map;
นำเข้า org.apache.http.httpresponse;
นำเข้า org.apache.http.client.responseHandler;
นำเข้า org.apache.http.client.entity.urlencodedformentity;
นำเข้า org.apache.http.client.methods.httpget;
นำเข้า org.apache.http.client.methods.httppost;
นำเข้า org.apache.http.impl.client.basicResponseHandler;
นำเข้า org.apache.http.impl.client.defaulthttpClient;
นำเข้า org.apache.http.message.basicnamevaluepair;
นำเข้า org.apache.http.message.bufferedheader;
นำเข้า org.apache.http.protocol.http;
นำเข้า com.util.Constant;
คลาสสาธารณะ JD {
// รายการการกำหนดค่า
redirecturl สตริงแบบคงที่ส่วนตัว = "http://order.jd.com/center/list.action";
สตริงคงที่ส่วนตัว loginUrl = "http://passport.jd.com/uc/login";
// อย่าเปลี่ยน URL ต่อไปนี้
สตริงคงที่ส่วนตัว renrenloginurl = "https://passport.jd.com/uc/loginservice";
// httpClient ใช้ในหนึ่งเซสชัน
การตอบสนอง httpresponse ส่วนตัว;
private defaulthttpClient httpClient = ใหม่ defaulthttpClient ();
แผนที่สาธารณะ <สตริงสตริง> getParams () {
แผนที่ <สตริงสตริง> แผนที่ = ใหม่ hashmap <สตริงสตริง> ();
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> <อินพุตประเภท =/" hidden/"name =" ");
String strs4 [] = str3s [1] .split ("/>");
String strs5 [] = strs4 [0] .trim (). แยก ("/" ");
String key = strs5 [0];
ค่าสตริง = strs5 [2];
map.put (คีย์, ค่า);
แผนที่กลับ;
-
เข้าสู่ระบบบูลีนส่วนตัว () {
แผนที่แผนที่ = getParams ();
httppost httpost = ใหม่ httppost (renrenloginurl);
// พารามิเตอร์ทั้งหมดโพสต์ไปยังเว็บไซต์
รายการ <micalnamevaluePair> nvps = new ArrayList <MasicNameValuePair> ();
NVPS.ADD (ใหม่ BasicNameValuePair ("ReturnUrl", Redirecturl));
NVPS.ADD (ใหม่ BasicNameValuePair ("loginName", constant.username));
NVPS.ADD (ใหม่ BasicNameValuePair ("nloginpwd", constant.password));
NVPS.ADD (ใหม่ BasicAnmeValuePair ("LOGINPWD", ค่าคงที่ PASS.WORD));
iterator it = map.keyset (). iterator ();
ในขณะที่ (it.hasnext ()) {
String key = it.next (). toString ();
ค่าสตริง = map.get (คีย์) .toString ();
NVPS.ADD (ใหม่ BasicNameValuePair (คีย์, ค่า));
-
พยายาม {
httpost.setEntity (urlencodedFormentity ใหม่ ((รายการ <? ขยาย org.apache.http.namevaluepair>) nvps, http.utf_8));
การตอบสนอง = httpClient.execute (httpost);
} catch (Exception e) {
E.PrintStackTrace ();
กลับเท็จ;
} ในที่สุด {
httpost.abort ();
-
กลับมาจริง;
-
สตริงส่วนตัว getRedirectLocation () {
Bufferedheader Locationheader = (Bufferedheader) Response.getFirstheader ("ตำแหน่ง");
if (locationHoheader == null) {
คืนค่า null;
-
กลับ locationheader.getValue ();
-
สตริงส่วนตัว getText (สตริง redirectLocation) {
httpget httpget = ใหม่ httpget (redirectlocation);
ResponseHandler <string> ResponseHandler = ใหม่ BasicResponseHandler ();
String ResponseBody = "";
พยายาม {
ResponseBody = httpClient.execute (httpget, responsehandler);
} catch (Exception e) {
E.PrintStackTrace ();
ResponseBody = null;
} ในที่สุด {
httpget.abort ();
//httpclient.getConnectionManager (). shutdown ();
-
return responsebody;
-
Public Void PrintText () {
ถ้า (เข้าสู่ระบบ ()) {
System.out.println (getText (redirecturl));
String redirectLocation = getRedirectLocation ();
if (redirectLocation! = null) {
System.out.println (getText (redirectLocation));
-
-
-
โมฆะคงที่สาธารณะหลัก (สตริง [] args) {
JD Renren = new JD ();
//renren.getParams ();
renren.printtext ();
-
-